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

Re: Why this expansion doesn't work?

On Mar 13, 10:39am, DervishD wrote:
} > What you should see is "Hellon", not "Hello".
}     That's weird :(( I still have open the console where I saw that,
} but in a new virtual console that doesn't happen

Cosmic rays.

} > The first parse removes the quotes and one of the backslashes, and the
} > second parse removes the remaining backslash.
}     So I must use something like:
}     eval printf -- \"Hello\\n\"

Yes, except of course that means something considerably different when
there are spaces or metacharacters in the (no longer double-quoted on
the first parse) string.  More likely you want

	eval printf -- \""Hello\\n"\"

}     I forgot that the double quotes were removed :((( Is there any
} way of seeing how a command line is parsed *just before* being
} executed by the shell?

setopt xtrace

(or the equivalent "set -x").  Note that xtrace in recent versions of
zsh re-quotes the output so that it's suitable for cut-and-paste; old
versions (4.0.x and before) show the fully-unquoted result, but there
it's difficult to see where the shell split strings into words.

So e.g.

zagzig% set -x
zagzig% eval printf -- \""Hello\\n"\"
+Src/zsh:2> eval printf -- '"Hello\n"'
+(eval):1> printf -- 'Hello\n'

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