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

Re: Something like noglob to inhibit brace expansion?

On Oct 6,  1:19pm, Lloyd Zusman wrote:
} Hmm ... isn't one of the three arguments passed to preexec already the
} raw, unexpanded command?  If so, is there a way to use preexec to modify
} the command line that is about to be executed?

There is not.  We considered that, but my experience with a similar hook
in the zmail scripting language led me to recommend against it.  It's
much too easy to get yourself into a state where the shell doesn't work
at all because a typo in preexec breaks or disables everything.

However, you could do this:

    preexec() {
    	setopt localoptions noksharrays
	typeset -gH _DONE_=0
	local -a cmd
	cmd=( ${(z)1} )
	if [[ $cmd[1] == raw ]]
	    if [[ $cmd[2] == '{' && $cmd[-1] == '}' ]]
		eval $cmd[3] "${(@q)cmd[4,-2]}"
	    elif [[ -z ${(M)cmd#([;|&]|&&|\{|\|\|)} ]]
		eval $cmd[2] "${(@q)cmd[3,-1]}"
		print -u2 raw: syntax error: all bets are off
    alias raw='((_DONE_)) ||'

This allows you to write stuff like

    raw echo this must be a simple $(command) but is *not* expanded
    raw { echo this must parse OK but is $(not expanded); echo see? }

But note that

    echo raw has no effect ; raw echo in the middle like this

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