* 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
* 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
* Re: Quoting in zsh -x output 2002-07-30 16:26 Hrvoje Niksic @ 2002-07-30 17:03 ` Peter Stephenson 2002-07-30 20:50 ` Dan Nelson 0 siblings, 1 reply; 6+ messages in thread From: Peter Stephenson @ 2002-07-30 17:03 UTC (permalink / raw) To: zsh-workers Hrvoje Niksic wrote: > I suggest modifying the zsh `-x' output to quote its arguments the way > Bash does. What do the others think? This would be nice, but it's not a trivial change. The xtrace output is done at the last minute after quoting information has been stripped. This is deliberate, in order to output exactly what is being evaluated after all substitutions, which is the information you can't get any other way. This is at odds with showing all the quotes. It's possible there's some compromise position which would show a lot of everything --- the quotes get stripped at quite a late stage. However, there's no way of doing it perfectly without a great deal of work --- consider expansions like "$@". You could try the `verbose' option, which works at the input end of the command chain. (In case anybody assumes otherwise, I have zero time to work on this myself for the foreseeable future.) -- Peter Stephenson <pws@csr.com> Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 392070 ********************************************************************** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. ********************************************************************** ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Quoting in zsh -x output 2002-07-30 17:03 ` Peter Stephenson @ 2002-07-30 20:50 ` Dan Nelson 2002-07-31 9:42 ` Peter Stephenson 0 siblings, 1 reply; 6+ messages in thread From: Dan Nelson @ 2002-07-30 20:50 UTC (permalink / raw) To: Peter Stephenson; +Cc: zsh-workers [-- Attachment #1: Type: text/plain, Size: 1500 bytes --] In the last episode (Jul 30), Peter Stephenson said: > Hrvoje Niksic wrote: > > I suggest modifying the zsh `-x' output to quote its arguments the > > way Bash does. What do the others think? > > This would be nice, but it's not a trivial change. The xtrace output > is done at the last minute after quoting information has been > stripped. This is deliberate, in order to output exactly what is > being evaluated after all substitutions, which is the information you > can't get any other way. This is at odds with showing all the > quotes. It's possible there's some compromise position which would > show a lot of everything --- the quotes get stripped at quite a late > stage. However, there's no way of doing it perfectly without a great > deal of work --- consider expansions like "$@". I think all bash does is check each argument for spaces, single-quotes, or backslashes, and then quotes and escapes that argument. It doesn't care what quoting the user had on the commandline: $ echo one\ two 'one two' "one two" + echo 'one two' 'one two' 'one two' I did a quick hack that replaced a bunch of fprintf/zputs with quotedzputs, and it seems to work fine. It ends up quoting "one'two" as 'one'\''two' for some reason, single-quoting "one", backslash-escaping "'", and single-quoting "two". Weird, but valid. This is my first zsh hack, and I'm probably doing everything wrong, but it shows that it's really not difficult. Even "$@" works. -- Dan Nelson dnelson@allantgroup.com [-- Attachment #2: patch-dn-xtrace --] [-- Type: text/plain, Size: 2567 bytes --] --- Src/builtin.c~ Tue Oct 16 04:49:17 2001 +++ Src/builtin.c Tue Jul 30 15:01:53 2002 @@ -356,10 +356,14 @@ execbuiltin(LinkList args, Builtin bn) if (xtr) { printprompt4(); fprintf(xtrerr, "%s", name); - if (xarg) - fprintf(xtrerr, " %s", xarg); - while (*oargv) - fprintf(xtrerr, " %s", *oargv++); + if (xarg) { + fputc(' ', xtrerr); + quotedzputs(xarg, xtrerr); + } + while (*oargv) { + fputc(' ', xtrerr); + quotedzputs(*oargv++, xtrerr); + } fputc('\n', xtrerr); fflush(xtrerr); } --- Src/cond.c~ Wed Oct 24 11:03:02 2001 +++ Src/cond.c Tue Jul 30 15:29:48 2002 @@ -147,9 +147,14 @@ evalcond(Estate state) singsub(&rt); untokenize(rt); } - fprintf(xtrerr, " %s %s %s", left, condstr[ctype], rt); - } else - fprintf(xtrerr, " -%c %s", ctype, left); + fputc(' ',xtrerr); + quotedzputs(left, xtrerr); + fprintf(xtrerr, " %s ", condstr[ctype]); + quotedzputs(rt, xtrerr); + } else { + fprintf(xtrerr, " -%c ", ctype); + quotedzputs(left, xtrerr); + } } if (ctype >= COND_EQ && ctype <= COND_GE) { --- Src/exec.c.orig Wed Oct 24 06:16:32 2001 +++ Src/exec.c Tue Jul 30 14:56:50 2002 @@ -1275,7 +1275,7 @@ makecline(LinkList list) for (node = firstnode(list); node; incnode(node)) { *ptr++ = (char *)getdata(node); - zputs(getdata(node), xtrerr); + quotedzputs(getdata(node), xtrerr); if (nextnode(node)) fputc(' ', xtrerr); } @@ -1544,8 +1544,10 @@ addvars(Estate state, Wordcode pc, int e untokenize(peekfirst(vl)); val = ztrdup(ugetnode(vl)); } - if (xtr) - fprintf(xtrerr, "%s ", val); + if (xtr) { + quotedzputs(val, xtrerr); + fputc(' ', xtrerr); + } if (export && !strchr(name, '[')) { if (export < 0 && isset(RESTRICTED) && (pm = (Param) paramtab->removenode(paramtab, name)) && @@ -1583,8 +1585,10 @@ addvars(Estate state, Wordcode pc, int e *ptr = NULL; if (xtr) { fprintf(xtrerr, "( "); - for (ptr = arr; *ptr; ptr++) - fprintf(xtrerr, "%s ", *ptr); + for (ptr = arr; *ptr; ptr++) { + quotedzputs(*ptr, xtrerr); + fputc(' ', xtrerr); + } fprintf(xtrerr, ") "); } setaparam(name, arr); @@ -3187,7 +3191,7 @@ execshfunc(Shfunc shf, LinkList args) for (lptr = firstnode(args); lptr; incnode(lptr)) { if (lptr != firstnode(args)) fputc(' ', xtrerr); - fprintf(xtrerr, "%s", (char *)getdata(lptr)); + quotedzputs((char *)getdata(lptr), xtrerr); } fputc('\n', xtrerr); fflush(xtrerr); ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Quoting in zsh -x output 2002-07-30 20:50 ` Dan Nelson @ 2002-07-31 9:42 ` Peter Stephenson 2002-07-31 14:55 ` Bart Schaefer 0 siblings, 1 reply; 6+ messages in thread From: Peter Stephenson @ 2002-07-31 9:42 UTC (permalink / raw) To: Zsh hackers list Dan Nelson wrote: > I think all bash does is check each argument for spaces, single-quotes, > or backslashes, and then quotes and escapes that argument. It doesn't > care what quoting the user had on the commandline: > > $ echo one\ two 'one two' "one two" > + echo 'one two' 'one two' 'one two' Ah, that's a different kettle of fish entirely. I don't see any problem including the patch. I doubt if anyone is attached to the current ambiguous behaviour of xtrace, are they? -- Peter Stephenson <pws@csr.com> Software Engineer CSR Ltd., Science Park, Milton Road, Cambridge, CB4 0WH, UK Tel: +44 (0)1223 392070 ********************************************************************** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. ********************************************************************** ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Quoting in zsh -x output 2002-07-31 9:42 ` Peter Stephenson @ 2002-07-31 14:55 ` Bart Schaefer 0 siblings, 0 replies; 6+ messages in thread From: Bart Schaefer @ 2002-07-31 14:55 UTC (permalink / raw) To: Zsh hackers list On Jul 31, 10:42am, Peter Stephenson wrote: } Subject: Re: Quoting in zsh -x output } } Dan Nelson wrote: } > I think all bash does is check each argument for spaces, single-quotes, } > or backslashes, and then quotes and escapes that argument. } } Ah, that's a different kettle of fish entirely. I don't see any problem } including the patch. I doubt if anyone is attached to the current } ambiguous behaviour of xtrace, are they? I don't have any particular problem with the patch -- though I'm not sure it covers all possible places where trace output is produced; I haven't checked -- but I would point out that there are a whole lot of things beyond mere argument quoting that prevent zsh's xtrace output from being cut'n'paste-able. Individual commands and their arguments might be, but for almost any more complex syntactic structure you're out of luck. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net ^ 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-08-03 17:05 Quoting in zsh -x output Hrvoje Niksic -- strict thread matches above, loose matches on Subject: below -- 2002-07-30 16:26 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
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).