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
Use eval
:
eval ${install_cmd}
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.