I’m evaluating whether or not certain variables match expected values. The variables are set in memory by a certain program, the values of which can be access from the shell with a custom program.
I’m piping the output of the shell command to awk to get the specific field I want and then I want to run it through perl to see if it matches the expected value. For example,
ysgrp autostart | awk -F\: '{print $1}' | perl -e 'print {"True"} else {print "False"} if /on/'
However, I’m getting complaints from perl about compilation errors near “} else”. How does one handle if/then/else logic in a perl one-liner?
You can’t use an
elsecondition in a postfix conditional. You can either use a ternary conditional operator like this:Or use explicit blocks like this: