[RndTbl] shell quoting inside $( )?

Trevor Cordes trevor at tecnopolis.ca
Mon Feb 27 23:43:33 CST 2023


On 2023-02-27 Gilbert Detillieux wrote:
> Rethinking the problem a bit, I came up with the following, which may
> or may not be an improvement over what others have already
> suggested...
> 
> T=$(openssl x509 -noout -text -in "$1" | sed -n 's/^.*Not After : 
> /EXPD=/p;s/^.*Subject: .*CN *= */SUBJ=/p' | sed "s/=\(.*\)/='\1'/")
> eval $T
> EXPD=$(date -d"$EXPD" +%Y%b%d)

Points lost for not-a-one-liner  ;-)

But you were smart to eliminate the multi-stream (tee >()) ideas, and
thus the async-order issue.  And save some forks.

NOW, the near-ideal way is to do what you did but see if sed has a regex
PCRE /e style exec option which you could then use to run the date from
within the regex itself.  Quoting might get hairy in that case, but it
would allow it to go back to just 1 line!

Perl could do it (with the eval, or pipe into read) and I might give
that a try for fun.

(In any case, you can save a line by putting the eval around line 1, no
need for $T.)

Does no one know how to get FD 3 & 4 used inside the >()'s and thus be
able to pass it (I think) out of the <()'s and capture again in the
root-shell context with a read thus eliminating the eval?

Is this a pipe dream? something like (pseudocode):

(openssl | tee >(sed foo|date >3) >(sed subj >4) ) | read -u3 expd | read -u4 subj

???


More information about the Roundtable mailing list