LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 10-12-2006, 01:42 AM   #1
Sundaram
LQ Newbie
 
Registered: Oct 2006
Posts: 12

Rep: Reputation: 0
Call One shell script from another shell script


Hi Everybody

I am new for Shell scripts in Linux.

I am using Slackware Linux 10.

I have two shell scripts one.sh and two.sh from one.sh i am calling two.sh with one argument.

can you anybody tell me how I call two.sh from one.sh.


Thanks in advance.
Sundaram.V
 
Old 10-12-2006, 02:14 AM   #2
Electro
LQ Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
Try
. two.sh

Of course you need to specify the full path to two.sh if it is not in the same directory where one.sh is found.
 
Old 10-12-2006, 04:21 AM   #3
Sundaram
LQ Newbie
 
Registered: Oct 2006
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks for your help.

It is working if we call with out argument, but I want to pass one command line argument also

two.sh release or two.sh debug

I will handle this argument in two.sh.

Thanks
Sundaram.V
 
Old 10-12-2006, 05:44 AM   #4
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
. two.sh
or equivalently
source two.sh
performs "sourcing" of the 2nd script. This is similar to including and executing the code of two.sh as if it was inside one.sh (ie if two.sh defines functions, you can source two.sh in one.sh and then use those functions in one.sh).
This is not the same as just calling two.sh from one.sh (like if you were calling an executable or any
other standard command like "ls", etc).
To do that, just call two.sh with it's parameter:
/path/to/two.sh param1 param2 ...

Make sure that two.sh
1. is executable
2. has an appropriate path (unless it's in one of the directories of $PATH)

Catching two.sh's output can be done via backticks or similar syntax. Check the man pages of your shell for syntax details.
 
Old 10-12-2006, 06:15 AM   #5
//////
Member
 
Registered: Nov 2005
Location: Land of Linux :: Finland
Distribution: Pop!_OS && Windows 10 && Arch Linux
Posts: 832

Rep: Reputation: 350Reputation: 350Reputation: 350Reputation: 350
one.sh
Code:
#!/bin/bash

/root/Desktop/two.sh debug

sleep 5

/root/Desktop/two.sh release

exit 0
two.sh
Code:
#!/bin/bash

if [ "$#" -eq 1 ]; then
	ARG="$1"
fi

if [ "$ARG" = "release" ]; then

echo $ARG

fi

if [ "$ARG" = "debug" ]; then

echo $ARG

fi
That works in my box.

Cheers

//////
 
Old 10-13-2006, 03:59 AM   #6
Sundaram
LQ Newbie
 
Registered: Oct 2006
Posts: 12

Original Poster
Rep: Reputation: 0
Thanks

Thanks for your help

Now It is working.

Thankyou once again
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Makefile call shell script thllgo Programming 4 12-28-2005 09:51 AM
Shell Script call API treotan Programming 1 08-22-2005 10:59 PM
call a c program in a shell script jagman Programming 4 04-05-2005 04:58 PM
Call a shell script from php? jharper101 Programming 2 02-15-2005 12:51 AM
My shell script can't seem to call another script kakho Programming 3 04-17-2004 09:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration