execution of shell script

How can I execute another shell script from one?

Malay

Inside the script, place a command which calls for the execution of the inner script.

Like this

#! /bin/sh
#Inside the script outer.sh
#Calling script inner.sh within this.

sh /path/to/inner.sh

Instead of sh /path/to/inner.sh, you can write ./path/to/inner.sh

Vino

You can try as,

cat > script1
#!/bin/sh
ls
hostname
uname -a

cat > script2
. ./script1

# chmod 755 script2 (Needed to execute shell script)
# ./script2

or

# sh script2

hth.

This is a bad way to call a script, since it will override the #! at the beginning of the script, if the second script is written in a different shell this will fail.

Make sure the script to be called is executable and has the appropriate #! on the first line, then call it by giving the path to the script.

#!/bin/sh
#
# script1.sh
#
#
/path/to/script2/script2.sh

Agreed and well taken.

What about
./path/to/script2/script2.sh

Would that make a difference ?

vino

Only if the path to script2.sh is relative to the current working directory at the time that call is made.

for example, the full path to script2.sh is /home/someuser/bin/script2.sh

if the current working directory at the time script2 is called is say /home/someuser then you could call script2.sh by doing ./bin/script2.sh, however if you used ./home/someuser/bin/script2.sh is would not work becuase in log form that is saying run /home/someuser/home/someuser/bin/script2.sh which does not exist.

. /home/someuser/bin/script2.sh however is different, and that would execute the script in the current shell.