#!/bin/sh execute_cmd() { $($@) } execute_cmd export MY_VAR=my_val echo ${MY_VAR}
由于$()在子 shell 中执行,$MY_VAR因此在脚本运行的 shell 中没有正确设置。
$()
$MY_VAR
我的问题是,如何将导出命令传递给函数并在运行脚本的当前 shell 中执行它?
shell function
function ×1
shell ×1