linux - How to call a variable in a bash command line? -


i trying create little program me, 1 command, compile , run c program within ubuntu's terminal.

trying make fancier, added argument bash file can use c program want. how supposed go:

  • create variable store name of file
  • use variable compile program (to same file name)
  • use same name run file.

here code:

# usr/bin/bash filename=$1 cc -o $filename "$filename.c" ./$filename.out 

almost runs, problem still have in last line:

./$filename.out 

it doesn't seem use name of variable inside command executes final program.

i'm noob @ bash (let's haven't used in months).

cc -o foo output foo not foo.out. should double-quote variable expansions prevent ifs-splitting , globbing:

filename=$1 cc -o "$filename" "$filename.c" && ./"$filename" 

apart # /usr/bin/bash (unlike #!/usr/bin/bash) nothing. it's comment. whole thing run /bin/sh, not bash (but don't need bash, anyway).


Comments

Popular posts from this blog

html - How to custom Bootstrap grid height? -

javascript - pass values from mssql to views in node -

javascript - Understanding ExtJS Framework Syntax -