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

RE: Substitution Cruft



> OK.  This has been annoying me for some time.  I must be doing something
> wrong, or there must be an easier way in any case.  I want to run a
> command with command line options output from a shell substitution:
> 	lprec ${(Q)${(zf)$(sed -n 's/["\$]/\\&/g;s/^\([A-Za-
> z]\+\)=\(.\+\)$/--\L\1\E "\2"/;/^--[a-z-]\+/p' < $tmp)}} &
> what this does is read a file ($tmp) that looks like
> Option1: value1
> Option2: value2
> and turns this into
> --option1 "value1"
> --option2 "value2"
> and this is then passed to the command 'lprec'.
> Is there a simpler way than using ${(Q)${(zf)...}}?


Not sure if it simpler, but (all one line)

bor@itsrm2% echo
${${(f)"$(<foo)"}//(#b)[[:space:]]#([^[:space:]]##):[[:space:]](*)/--$match[
1] \"$match[2]\"}
--option1 "value 1" --option2 "value 2"

bor@itsrm2% cat foo
option1: value 1
option2: value 2

adjust spaces to taste (I do not know if value is separated by just one
space or starts with first non-space).

You need extended globbing turned on.

-andrey



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