zsh run a command stored in a variable?

前端 未结 2 1431
遇见更好的自我
遇见更好的自我 2021-02-13 04:03

In a shell script (in .zshrc) I am trying to execute a command that is stored as a string in another variable. Various sources on the web say this is possible, but I\'m not get

相关标签:
2条回答
  • 2021-02-13 04:55

    Use eval:

    eval ${install_cmd}
    
    0 讨论(0)
  • 2021-02-13 05:02

    As explained in §3.1 "Why does $var where var="foo bar" not do what I expect?" of the Z-Shell FAQ, you can use the shwordsplit shell option to tell zsh that you want it to split variables up by spaces and treat them as multiple words. That same page also discusses alternatives that you might want to consider.

    0 讨论(0)
提交回复
热议问题