[RndTbl] shell quoting inside $( )?

Adam Thompson athompso at athompso.net
Sun Feb 26 18:07:39 CST 2023


I’m trying to figure out if there’s a way to do this more compactly (for reasons…):

T=$(openssl x509 -noout -text -in "$1")
EXPD=$(date -d"$(echo "$T" | sed -n 's/^.*Not After : //p')" +%Y%b%d)
SUBJ=$(echo "$T" | sed -n 's/^.*Subject: .*CN = //p')

I am having two issues:

  1.  Bash doesn’t happily let me embed double quotes inside a subshell inside a subshell inside double-quotes.  All of the double-quotes are required, AFAICT.  So doing X=$(…”$(…”xxx”)”) just doesn’t work because bash doesn’t parse nested double-quotes.  But both the inner var and the result can and will have spaces in them.
  2.  I can’t remember how in shell (bash, in this case) how to bifurcate stdout and have it run to two pipelines.  I figure echo is a builtin, so should at least be lighter than re-running the monstrosity that is openssl over and over.  I have a vague recollection that this is harder than it sounds, and may not be worth it…

Any suggestions on how to solve either issue?  I’m sure I’ve just forgotten some obvious technique, hopefully someone can jog my mind.
-Adam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://muug.ca/pipermail/roundtable/attachments/20230227/a467353d/attachment.htm>


More information about the Roundtable mailing list