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 Internet say that this is possible, but I do not get the behavior that I expect. Maybe this is ~ at the beginning of the command, or maybe using sudo , I'm not sure. Any ideas? Thanks
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 }
Output:
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
scripting shell zsh
DC
source share