我很困惑;我运行一个脚本,使用 sh -c ,但如果我想传递一个参数,它将被忽略。
例:
# script.sh
param=$1
echo "parameter is: " $param
如果我运行它
sh -c ./script.sh 你好
我在输出中什么也没得到
为什么会这样?我怎样才能避免这种情况?
这将适用于您:
sh -c "./script.sh hello"
如果以这种方式运行它:
sh -c ./script.sh hello
比hello
成为sh
的第二个参数,./script.sh
运行时没有参数。
-c
开关接受单个参数。 外壳将自行执行解析。 例如
sh -c './script.sh hello'