Shell script hangs when i switch to bash - Linux -
this question has answer here:
i'm very new linux(coming windows) , trying write script can execute on multiple systems. tried use python fount hard too. here have far:
cd /bin bash source compilervars.sh intel64 cd ~ exit #exit bash file= "~/a.out" if[! -f "$file"] icc code.c fi #run commands here... the script hangs in second line (bash). i'm not sure how fix or if i'm doing wrong. please advice.
also, tips of how run script on multiple systems on same network?
thanks lot.
what believe you'd want do:
#!/bin/bash source /bin/compilervars.sh intel64 file="$home/a.out" if [ ! -f "$file" ]; icc code.c fi you put in file , make executable chmod +x myscript. run ./myscript. alternatively, run bash myscript.
your script makes little sense. second line open new bash session, sit there until exit it. also, changing directories , forth seldom required. execute single command in directory, 1 does
( cd /other/place && mycommand ) the ( ... ) tells shell you'd in sub-shell. cd happens within sub-shell , don't have cd after it's done. if cd fails, command not run.
for example: might want make sure you're in $home when compile code:
if [ ! -f "$file" ]; ( cd $home && icc code.c ) fi ... or pick out directory name variable file , use that:
if [ -f "$file" ]; ( cd $(dirname "$file") && icc code.c ) fi assigning variable needs happen wrote it, without spaces around =.
likewise, there needs spaces after if , inside [ ... ] wrote above.
i tend use $home rather ~ in scripts it's more descriptive.
Comments
Post a Comment