问题描述:

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

网友答案:

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
相关阅读:
Top