invoking one shell script from other

hi,

i am one day old in shell scritpting. how to invoke one shell script from the other?
For eg.i have two shell scripts A.sh and B.sh. Inside A.sh i need to invoke B.sh and the return code of A.sh should be the value returned by B.sh.

it would be better if you provide any sample shell scripts.

Thanks,
Ajay.

A.sh call B.sh

just put
B.sh
as a command in the shell script e.g.
cp ... ...
ls ... ...
B.sh

etc...

Remeber the user running the script must also has execute permission for B.sh

  1. The return value of A.sh
    is controlled by either
    exit <value>
    or the return code of the last command
    so if B.sh was you last command in A.sh then the return code of B.sh = return code of A.sh

However if you have more commands after B.sh in the script, you can save the return value of B.sh using

B.sh
retcode = $?
....
....
exit $retcode
(differs for whatever shell you use but $? is the return code of your last command.)

Hope it helps

Thanks for your reply. but still i am having some doubts

i went through some of the websites. its quoted that "use $? very rarely".

is it a good practice to use this? (pradon me if i am wrong i dont have much idea in scripting)

another similar problem is

assume that
./a.sh will gives some output

./a.sh>a.out will redirect the output to some file a.out

Now i want to do same from another script insted of directly writting in prompt.
contents of b.sh will be

`./a.sh>a.out`

now when i run b.sh output is echoed to the screen insted of writing to a.out.
How come? Some solution to this :frowning: