Linux: Run a binary in a script

co-worker picture co-worker · Oct 17, 2010 · Viewed 43.3k times · Source

i want to run a program via script. normally i type ./program in the shell and the program starts.

my script looks like this:

#!/bin/sh
cd  /home/user/path_to_the_program/
sh program

it fails, i think the last line went wrong...

i know this is childish question but thx a lot!

Answer

Nick picture Nick · Oct 17, 2010

If ./program works in the shell, why not use it in your script?

#!/bin/sh
cd /home/user/path_to_the_program/
./program

sh program launches sh to try and interpret program as a shell script. Most likely it's not a script but some other executable file, which is why it fails.