Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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)
share|improve this question

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

share|improve this answer

You must log in to answer this question.