46.5 Stop Syntax Errors in String Tests
Using the
test
or
if [ "$var" =
If One common fix (that doesn't always work; see below) is to put an extra character at the start of each side of the test. This means the first argument will never start with a dash; it won't look like an option:
if [ "X$var" = X That trick doesn't work if you want the test to fail when the variable is empty or not set. Here's a test that handles empty variables:
case "${var+X}" in X) ...do this if variable is set... ;; *) ...do this if variable is not set... ;; esac
If - |
|