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

Re: Substitution Cruft



On Sep 10,  3:21pm, Nikolai Weibull wrote:
}
} 	lprec ${(Q)${(zf)$(sed -n 's/["\$]/\\&/g;s/^\([A-Za-z]\+\)=\(.\+\)$/--\L\1\E "\2"/;/^--[a-z-]\+/p' < $tmp)}} &

} Is there a simpler way than using ${(Q)${(zf)...}}?

Without eliminating the $(sed ...) the best alternative is:

	eval lprec "$(sed ...)"

(Yes, the double quote in ["\$] is handled correctly even if you wrap the
whole $(...) in double quotes.)

The whole thing could be replaced (assuming default setopts shwordsplit
et al.) with:

	while read option value
	do arguments=( $arguments --${(L)option:s/://} $value )
	done < $tmp

	lprec $arguments &

which while it takes a few more lines is certainly less cryptic and does
not fork a process.  If for some reason you must write it as one line:

while read o v; do a=($a --${(L)o:s/://} $v); done < $tmp; lprec $a &

Even if you stick "local -a a; local o v;" on the front of that, it's
shorter than what you started with.



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