Linux
发布时间:2022-04-01 发布网站:大佬教程 code.js-code.com
大佬教程收集整理的这篇文章主要介绍了linux – 如何将参数传递给source命令调用的脚本?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
概述
我通过
source命令调用脚本,并希望将参数传递给脚本. 我检查了man
source,bash返回: : [arguments] No effect; the command does nothing beyond expanding arguments and performing any specified redirection
s. A zero exit code is returned
@H_
675_15@我通过
source命令
调用脚本,并希望将参数传递给脚本.
我检查了man source,bash返回:
它没有例子,所以我不明白.
使用以下
内容创建文件test.sh:
echo "I was given $# argument(s):"
printf "%s\n" "$@"
然后从交互式sHell会话中获取它:
$source ./test.sh a 'b c'
I was given 2 argument(s):
a
b c
所以你可以像在普通的bash脚本中一样访问参数,使用$@或$1,$2,$3等.
为了比较,将其作为常规脚本运行:
$bash ./test.sh a 'b c'
I was given 2 argument(s):
a
b c