[RndTbl] shell quoting inside $( )?

Adam Thompson athompso at athompso.net
Tue Feb 28 07:14:04 CST 2023


Wow, I think I unwittingly invoked Cunningham's Law with my initial post...

Thank you to everyone for the hints, tips, and alternate approaches - I've learned a few new things through this!

-Adam

Get Outlook for Android<https://aka.ms/AAb9ysg>
________________________________
From: Trevor Cordes <trevor at tecnopolis.ca>
Sent: Tuesday, February 28, 2023 12:42:55 AM
To: Gilbert Detillieux <Gilbert.Detillieux at umanitoba.ca>
Cc: Continuation of Round Table discussion <roundtable at muug.ca>; Adam Thompson <athompso at athompso.net>
Subject: Re: [RndTbl] shell quoting inside $( )?

Perl version.  Cleaner?  No eval.  No >().  One line.  Relies on
read to fill the bash vars.  Uses Gilbert's just-one-filter-pass
idea.  Does the date transform at the very end in perl: would be
a sec hole if $e is injected with bad things.  Could easily fix
with setting the $e regex from . to [-.a-zA-Z0-9].  Could also
die in the END if !$e.

$ read SUBJ EXPD <<<$(openssl x509 -noout -text -in /etc/pki/tls/certs/tecnopolis.ca.crt | perl -ne '($e)=/^.*Not After : (.*)/ if !$e; ($s)=/^.*Subject: .*CN = (.*)/ if !$s; END { print $s." ".`date -d"$e" +%Y%b%d`}')
$ echo s=$SUBJ e=$EXPD
s=tecnopolis.ca e=2024Feb22

I like the perl approach because it has the least # of forks, and
really the sky is the limit for taint cleaning and sanity checks.
Plus I find it more readable than bash, and perl is highly
optimized for PCRE so should be pretty fast.  I also understand
perl's quoting intimately vs my general haze with bash.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://muug.ca/pipermail/roundtable/attachments/20230228/e19f78fb/attachment-0001.htm>


More information about the Roundtable mailing list