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

Re: color codes to eval





On 2024-04-10 11:39, Lawrence Velázquez wrote:
# Avoid the pointless eval in the first place.
	print -l $var
The problem occurs in a deeper context where the eval can't be avoided, I just extracted the minimal example.
	# Delay all expansions.
	eval 'print -l $var'
Works!  And I believe I understand it.  '$var' *will* expand even though it doesn't look like it, because eval takes a second crack at the line after the single quotes are removed, yes?
	# Delay learning how quoting actually works.
	eval "print -l ${(q)var}"
I'll play with that further, that's the thing I was trying to remember.  First efforts are not working, but I do recall that '(q)' ended up giving me trouble down the line and was best avoided.  As to learning, that's what I'm trying to do.  Coming from DOS, the rules there are very different -- there's no preprocessing by the shell, command tails are passed to commands exactly as they are written.  It takes time to unlearn that.  It's almost hard coded into my brain.
	# Leave invalid patterns in the command.
	unsetopt BAD_PATTERN
	eval "print -l $var"
Looks dangerous!  Looks like bad practice.  But I'll experiment with it. 

But:" # Delay all expansions. eval 'print -l $var' ... looks like the proper answer. Thanks Lawrence.

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