Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Running system command fails but the same command works executed directly in bash

I am running the following code in perl

my $exp_date = `date --date="$(openssl x509 -enddate -noout -in certificate.pem | cut -d= -f 2)"  --iso-8601`; 

and I get:

date: invalid date ‘100 100 537 539 847 6210 70720 7….

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The exact command run in the command line

date --date="$(openssl x509 -enddate -noout -in certificate.pem | cut -d= -f 2)"  --iso-8601

prints the actual date in iso8601.

What am I doing wrong when running it in Perl?

>Solution :

The Perl special variable $( (see the documentation) contains the real group id of the process. Backticks interpolate variables. To prevent interpolation, escape the dollar sign by a backslash:

my $exp_date = `date --date="\$(openssl x509 -enddate -noout -in certificate.pem | cut -d= -f 2)"  --iso-8601`;
#                            ~
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading