当前位置: 动力学知识库 > 问答 > 编程问答 >

bash - Prevent parameter propagation

问题描述:

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
分享给朋友:
您可能感兴趣的文章:
随机阅读: