LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Call One shell script from another shell script (https://www.linuxquestions.org/questions/linux-software-2/call-one-shell-script-from-another-shell-script-491673/)

Sundaram 10-12-2006 01:42 AM

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

Electro 10-12-2006 02:14 AM

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.

Sundaram 10-12-2006 04:21 AM

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

timmeke 10-12-2006 05:44 AM

. 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.

////// 10-12-2006 06:15 AM

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

//////

Sundaram 10-13-2006 03:59 AM

Thanks
 
Thanks for your help

Now It is working.

Thankyou once again


All times are GMT -5. The time now is 11:49 PM.