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
Post a Comment