加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

shell – zsh运行存储在变量中的命令?

发布时间:2020-12-15 18:26:02 所属栏目:安全 来源:网络整理
导读:在 shell脚本(在.zshrc中)我试图执行一个命令,该命令作为字符串存储在另一个变量中.网络上的各种消息来源说这是可能的,但我没有得到我期望的行为.也许这是命令开头的?,或者也许是使用sudo,我不确定.有任何想法吗?谢谢 function update_install(){ # builds
在 shell脚本(在.zshrc中)我试图执行一个命令,该命令作为字符串存储在另一个变量中.网络上的各种消息来源说这是可能的,但我没有得到我期望的行为.也许这是命令开头的?,或者也许是使用sudo,我不确定.有任何想法吗?谢谢
function update_install()
{
    # builds up a command as a string...
    local install_cmd="$(make_install_command $@)"
    # At this point the command as a string looks like: "sudo ~some_server/bin/do_install arg1 arg2"
    print "----------------------------------------------------------------------------"
    print "Will update install"
    print "With command: ${install_cmd}"
    print "----------------------------------------------------------------------------"
    echo "trying backticks"
    `${install_cmd}`
    echo "Trying $()"
    $(${install_cmd})
    echo "Trying $="
    $=install_cmd
}

输出:

Will update install
With command: sudo ~some_server/bin/do_install arg1 arg2

trying backticks
update_install:9: no such file or directory: sudo ~some_server/bin/do_install arg1 arg2
Trying $()
update_install:11: no such file or directory: sudo ~some_server/bin/do_install arg1 arg2
Trying $=
sudo ~some_server/bin/do_install arg1 arg2: command not found
使用eval:
eval ${install_cmd}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读