Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Quoting in zsh -x output

Bash has a nice feature of its `-x' output: the arguments that contain
whitespace or shell metacharacters are quoted, which allows one to
copy the output and paste it into another shell.  I find this very

Here is an example:

bash$ set -x
bash$ echo "foo bar"
+ echo 'foo bar'
foo bar
bash$ echo "foo*"
+ echo 'foo*'
bash$ echo "foo'bar"
+ echo 'foo'\''bar'
bash$ echo "foo"
+ echo foo

The last example shows that the quotes are printed only when needed.
Arguments containing whitespace and metacharacters are quoted, and
embedded single quotes are handled correctly.  This makes sure that
pasting the output produces the same results.

Zsh, on the other hand, prints this:

zsh$ set -x
zsh$ echo "foo bar"
+zsh:2> echo foo bar
foo bar
zsh$ echo "foo*"
+zsh:3> echo foo*
zsh$ echo "foo'bar"
+zsh:4> echo foo'bar
zsh$ echo "foo"
+zsh:5> echo foo

I suggest modifying the zsh `-x' output to quote its arguments the way
Bash does.  What do the others think?

Messages sorted by: Reverse Date, Date, Thread, Author