zsh-users
 help / color / mirror / code / Atom feed
* Substitution Cruft
@ 2003-09-10 13:21 Nikolai Weibull
  2003-09-10 14:31 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Nikolai Weibull @ 2003-09-10 13:21 UTC (permalink / raw)
  To: Zsh Users

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)...}}?
	nikolai

--
::: name: Nikolai Weibull    :: aliases: pcp / lone-star / aka :::
::: born: Chicago, IL USA    :: loc atm: Gothenburg, Sweden    :::
::: page: www.pcppopper.org  :: fun atm: gf,lps,ruby,php,war3  :::
main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}


^ permalink raw reply	[flat|nested] 4+ messages in thread
* RE: Substitution Cruft
@ 2003-09-10 13:57 Borzenkov Andrey
  0 siblings, 0 replies; 4+ messages in thread
From: Borzenkov Andrey @ 2003-09-10 13:57 UTC (permalink / raw)
  To: 'Nikolai Weibull', 'Zsh Users'


> 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-09-10 16:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-10 13:21 Substitution Cruft Nikolai Weibull
2003-09-10 14:31 ` Bart Schaefer
2003-09-10 16:54   ` Nikolai Weibull
2003-09-10 13:57 Borzenkov Andrey

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).