Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果您在 KornShell 脚本中传递了一个参数,并且它也是一个命令,例如:
ksh argument.ksh "wc -l"
您将如何在脚本中执行此命令?您是否将其存储在变量中,然后执行它?另外,有没有办法通过在脚本中执行命令来检索标准输出/标准错误?
把它放在你的 argument.ksh 脚本中:
echo "Running command $1." ## optional message eval "$1" ## evaluate "$1" as a whole new command
实际上更好或更安全的方法是使用"$@":
"$@"
echo "Running command $*." ## optional message "$@"
并像这样传递你的论点:
ksh argument.ksh wc -l