i writing on script greps regular expression , includes regular expression variable. there seems lay problem.
script ($hostname argument command line , can i.e. google.com):
tldlist="$(curl -s http://data.iana.org/tld/tlds-alpha-by-domain.txt | grep -v '#' | tr '\n' '|' | sed 's/|$//g')" curl="$(curl -vfik https://$hostname 2>&1 | sed 's/^\* \t //g' | grep -i -o --color=never -e \"cn=\(.*\)\.\($tldlist\)\")" expiration="`curl -vfik https://$hostname 2>&1 | sed 's/^\* \t //g' | grep -i -e --color=never '(start|expire)'`" echo "$curl" echo "$expiration"
it not match part common name in output of curl. if write regex manually, works , matches successfully.
so question is: how solve regex problem inside bash?
update
tried write in way, works (basically):
curl=$(curl -vfik https://$hostname 2>&1 | sed 's/^\* \t //g' | grep -i -o --color=never -e "cn=(.*)\.($tldlist)")
the problem lays @ escaping quotes , brackets. have put output of command double quotes due multiline variables (not line above, gives 1 line).
but still:
there question how solve escape/regex/variable problem.
the immediate problem not regex issue. have $tldlist
variable inside single quotes, , single quotes prevent variable expansion. change second line to, e.g.:
curl="$(curl -vfik https://$hostname 2>&1 | sed 's/^\* \t //g' | tr '[a-z]' '[a-z]' | grep -i --color=never -e "cn=\(.*\)\.$tldlist")"
so allow $tldlist
expand.
Comments
Post a Comment