19,615
社区成员
发帖
与我相关
我的任务
分享
bash-3.2$ greet="echo hello $1"
bash-3.2$ ($greet world)
hello world
bash-3.2$ greet="if [ 1 == 1 ]; then echo hello $1; fi"
bash-3.2$ ($greet world)
bash: if: command not found
bash-3.2$ eval $greet
hello
bash-3.2$ eval $greet world
bash: syntax error near unexpected token `world'
bash-3.2$ greet="if [ 1 == 1 ]; then echo hello $1; fi"
bash-3.2$ ($greet world)
bash-3.2$ hello world
,把 “函数调用(内部包含传参过程)”分解成“参数设置+eval 执行命令”两个子过程。
PS#1,stack overflow上好像在让楼主该一下问题描述,加上为什么不使用函数的原因,以避免被标记为duplicate。
PS#2,()是个必要元素吗?