The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
problem with shell script execution anju Shell Programming and Scripting 2 05-08-2008 01:50 AM
Sequential execution in shell script? chengwei UNIX for Dummies Questions & Answers 6 03-30-2007 12:10 AM
Scheduling the execution of a shell script sumesh.abraham Shell Programming and Scripting 1 12-06-2006 07:25 AM
Logging OWB mapping execution in Shell script npn Shell Programming and Scripting 1 11-16-2006 09:25 AM
Please help on shell scripts execution duke0001 Shell Programming and Scripting 13 09-20-2006 03:31 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-13-2005
malaymaru malaymaru is offline
Registered User
  
 

Join Date: May 2005
Posts: 54
execution of shell script

How can I execute another shell script from one?

Malay
  #2 (permalink)  
Old 06-13-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
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 (permalink)  
Old 06-13-2005
muthukumar muthukumar is offline
Registered User
  
 

Join Date: Feb 2005
Location: Coimbatore, Tamilnadu, India
Posts: 119
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 (permalink)  
Old 06-13-2005
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
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 (permalink)  
Old 06-13-2005
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
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 (permalink)  
Old 06-13-2005
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,206
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:08 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0