zsh-workers
 help / color / mirror / code / Atom feed
* Quoting in zsh -x output
@ 2002-07-30 16:26 Hrvoje Niksic
  2002-07-30 17:03 ` Peter Stephenson
  0 siblings, 1 reply; 6+ messages in thread
From: Hrvoje Niksic @ 2002-07-30 16:26 UTC (permalink / raw)
  To: zsh-workers

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
useful.

Here is an example:

bash$ set -x
bash$ echo "foo bar"
+ echo 'foo bar'
foo bar
bash$ echo "foo*"
+ echo 'foo*'
foo*
bash$ echo "foo'bar"
+ echo 'foo'\''bar'
foo'bar
bash$ echo "foo"
+ echo foo
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*
foo*
zsh$ echo "foo'bar"
+zsh:4> echo foo'bar
foo'bar
zsh$ echo "foo"
+zsh:5> echo foo
foo

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


^ permalink raw reply	[flat|nested] 6+ messages in thread
* Quoting in zsh -x output
@ 2002-08-03 17:05 Hrvoje Niksic
  0 siblings, 0 replies; 6+ messages in thread
From: Hrvoje Niksic @ 2002-08-03 17:05 UTC (permalink / raw)
  To: zsh-workers

Thanks for looking into this.  Dan, you are correct in your conclusion
that I didn't ask for the original quoting to be preserved, but only
for quoting to be consistent.  The examples I gave in fact confirmed
that.  I hope the patch will go in; thanks for writing it.

Bart, I agree that this patch will not allow pasting of more complex
syntactic constructs.  But that's not the case in Bash either, and I'm
not sure if it's even generally possible with -x.  Being able to
correctly copy one command is already (IMHO) a great thing.

For example, I have a fairly complex script called `reencode' that
accepts simple arguments and uses them to construct the complex
command line with which to call the actual encode utility, `mencoder'.
For debugging and educational purposes, it's useful to see what the
script is doing.  The way I did it is:

    set -x
    mencoder $foo_opts $bar_opts_maybe -o "$dest" "$source" ...
    set +x

With this I get a `make'-like feature of seeing the commands that are
being run.  Full quoting of output brings this to the next level: it
allows me to rerun the command manually, possibly after making a small
adjustment to the options.  `make' doesn't support this, but it's
really neat and very easy to get used to.

Again, thanks for implementing this.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2002-08-03 17:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-30 16:26 Quoting in zsh -x output Hrvoje Niksic
2002-07-30 17:03 ` Peter Stephenson
2002-07-30 20:50   ` Dan Nelson
2002-07-31  9:42     ` Peter Stephenson
2002-07-31 14:55       ` Bart Schaefer
2002-08-03 17:05 Hrvoje Niksic

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).