...
Code Block | ||
---|---|---|
| ||
dat=$( cat not_a_file ) if [[ "$dat" == "" ]]; then echo "ERROR: no data found" 1>&2; exit 255 else echo "Data is: '$dat'" fi # or using -z to test for an empty string if [[ -z "$dat" ]]; then echo "ERROR: no data found" 1>&2; exit 255; else echo "Data is '$dat'"; fi |
See https://www.gnu.org/software/bash/manual/html_node/Bash-Conditional-Expressions.html for conditional expressions, and https://www.gnu.org/software/bash/manual/html_node/Conditional-Constructs.html for conditional constructs such as if or case.
Setting environment variables for a script
...