In uno script di shell (in .zshrc) Sto tentando di eseguire un comando che è memorizzato come una stringa in un'altra variabile. Varie fonti sul web dicono che è possibile, ma non sto ottenendo il comportamento che mi aspetto. Forse è il ~
all'inizio del comando, o forse è l'uso di sudo
, non ne sono sicuro. Qualche idea? Graziezsh esegue un comando memorizzato in una variabile?
function update_install()
{
# builds up a command as a string...
local install_cmd="$(make_install_command [email protected])"
# 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
}
uscita:
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
potresti usare 'zsh -c '$ {install_cmd}'' – Alex