4

I am trying to run tmux, passing several commands at once, and I'm unable to properly quote the string.

The command succeeds when manually entered on the command line:

~% /usr/local/bin/tmux start-server\; set-option -g default-command '/usr/bin/true 1 2 3' \; new-session
[exited]

But in the real case, I need to build the command dynamically, and then I'm unable to get it to expand correctly. The single quotes seem to get discarded during the ${=var} expansion:

 ~% cmd="/usr/local/bin/tmux start-server; set-option -g default-command '/usr/bin/true 1 2 3' ; new-session"
 ~% ${=cmd}
usage: set-option [-agosquw] [-t target-session|target-window] option [value]

tmux doesn't understand the command when passed as a single string, i.e. not including the /usr/local/bin/tmux token in the string, and expanding the rest using ${cmd} as opposed to ${=cmd}.

~% /usr/local/bin/tmux 'start-server; set-option -g default-command "/usr/bin/true 1 2 3"; new-session'
unknown command: start-server; set-option -g default-command "/usr/bin/true 1 2 3"; new-session

my zsh version:

⚠~% ${SHELL} --version
zsh 5.0.2 (x86_64-apple-darwin12.2.1)

1 Answer 1

3

${(z)var} expands the variable while keeping the inner quotes intact.

You must log in to answer this question.