execution of shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting execution of shell script
# 1  
Old 06-13-2005
execution of shell script

How can I execute another shell script from one?

Malay
# 2  
Old 06-13-2005
Inside the script, place a command which calls for the execution of the inner script.

Like this

Code:
#! /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
# 3  
Old 06-13-2005
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.
# 4  
Old 06-13-2005
Quote:
sh /path/to/inner.sh
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.

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

# 5  
Old 06-13-2005
Quote:
Originally Posted by reborg
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.
Agreed and well taken.


Quote:
Originally Posted by reborg
Code:
#!/bin/sh
#
# script1.sh
#
#
/path/to/script2/script2.sh

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

Would that make a difference ?

vino
# 6  
Old 06-13-2005
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Script on Solaris spawning 2 processes for one shell script execution

Hi, I am having a shell script on Solaris 10 which has a while loop as shown below. #!/usr/bin/ksh # while do sleep 60 done Name of the shell script is coldcentric.sh. I executed script /DATAWAREHOUSE/LOAD/Scripts/coldcentric.sh from a command task in Informatica worklow as... (3 Replies)
Discussion started by: chekusi
3 Replies

2. Shell Programming and Scripting

Shell Script execution issues

Hi, There's a shell script by name "download", which has been created as user "mgr" and that script needs to executed as user "dev". I tried giving privileges 701 on the script download. But it's throwing the error message bin]$ ./download /bin/bash: ./download: Permission denied ... (6 Replies)
Discussion started by: venkatesh17
6 Replies

3. UNIX for Dummies Questions & Answers

shell script execution in ab initio

Hi All, How to execute shell script for running Ab initio graphs? Regards (0 Replies)
Discussion started by: eshalife
0 Replies

4. UNIX for Dummies Questions & Answers

Shell script execution methods

Hi, Shell script can be executed in few ways. I would like to know the differences in the below execution methods. sh file1.sh . file1.sh . /file1.sh Please help, thank you. (2 Replies)
Discussion started by: Dev_Dev
2 Replies

5. UNIX for Advanced & Expert Users

SSH using shell script terminates the script execution

Hello, I am writing a shell script in which i do ssh to remote server and count the number of files there and then exit. After the exit the shell script terminates which i believe is expected behavior. Can some one suggest me a way where even after the exit the script execution resumes. ... (2 Replies)
Discussion started by: manaankit
2 Replies

6. Shell Programming and Scripting

Execution problem with shell script

Hi all, I want to use perl string manipulation commands in my shell script. I have written following script. echo "enter name" read name perl -e '$m=length($name); echo $m it gives an error: unrecognized token in perl command line. do not suggest me an equivalent command of shell... (3 Replies)
Discussion started by: admc123
3 Replies

7. Shell Programming and Scripting

Cron execution of shell script

Hi Guys, Unable to run this script from the cron,although the same executes perfectly from the command line.Please help. #!/bin/sh #### aprintd alarm creation files ##### file=`date +%m%d%Y` pid=$$ echo "$pid" /u01/app/netboss/bin/aprintd/aprintd > $file & childpid=$!... (3 Replies)
Discussion started by: ashish.sharma
3 Replies

8. Shell Programming and Scripting

problem with shell script execution

Hi All, i am running a shell script in which there is a command `ps -ef | grep smon > db` When i execute this command in the command prompt i am getting the desired output..but when the script is executed..the db file is getting created but with no values...I could not find the reason for... (2 Replies)
Discussion started by: anju
2 Replies

9. UNIX for Dummies Questions & Answers

Is there a way to tell how long does a shell script's execution take?

Is there a way to tell how long does a shell script(or a shell command)'s execution take? (4 Replies)
Discussion started by: meili100
4 Replies

10. UNIX for Dummies Questions & Answers

Sequential execution in shell script?

I've a shell script that invokes a URL of an application to do some work, e.g., http://www.abc.com/myservlet?action=helloworld.Does the shell wait for a return value from the URL call before proceeding to the next line of command? (6 Replies)
Discussion started by: chengwei
6 Replies
Login or Register to Ask a Question