Reputation: 195
When I call a script inside another one, the parameters I give to the first one are automatically propagate to the second one.
a.sh :
echo "a running"
source b.sh blablabla
source b.sh
b.sh :
echo "b running"
echo $1
Which gives :
$source a.sh hello
a running
b running
blablabla
b running
hello
EDIT :
set ""
echo "a running"
source b.sh blablabla
source b.sh
Can be a solution since set "" set the first parameter to an empty string
Upvotes: 0
Views: 154
Reputation: 11796
When you use source
, everything inside b.sh is being read and executed as if it were part of a.sh - so it has access to the positional parameters passed to a.sh. What are you trying to accomplish here - is it actually necessary to use source
? You can avoid this behaviour by running the script instead of sourcing it:
./b.sh
Or:
bash b.sh
Upvotes: 4