![](/img/trans.png)
[英]Calling one Bash script from another Script passing it arguments with quotes and spaces
[英]BASH:Passing arguments from one shebang to another
我有两个脚本。
temp.sh
#! /usr/bin/foo
echo "$@"
FOO
#! /usr/bin/bash
source "$@"
除了在以下情况下temp.sh在其shebang中具有参数的情况下,此方法有效。
temp.sh
#! /usr/bin/foo -x
echo "$@"
这使其成为问题。
/root/foo: line 4: source: -x: invalid option
source: usage: source filename [arguments]
无论如何,我可以将传递给temp.sh的shebang的-x(或就此而言,所有参数)传递给foo的shebang吗?
如果要使用第一个参数并将其与特定的一组模式匹配时将其传递给外壳解释器,则可以自己执行以下操作:
# treat first argument of -x or -v as intended for the shell interpreter
case $1 in -[xv]) set "$1"; shift;; esac
source "$@"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.