Issue
While the condition did not pass in the TRUE result. What's wrong with the syntax?
RESULT="Exited (0) Less than a second ago"
if [ "$RESULT" = "Exited (0) Less than a second ago" || "$RESULT" = "Stop" ]
then
echo 'exited'
elif [ "$RESULT" = *"Up"* ]
then
echo 'stopped and exited'
else
echo 'Docker already removed'
fi
Solution
The following script works properly based on the provided conditions.
#!/bin/sh
RESULT="Exited (0) Less than a second ago"
if [ "$RESULT" = "Exited (0) Less than a second ago" ] || [ "$RESULT" = "Stop" ]; then
echo 'exited'
elif [ "$RESULT" = "Up" ]; then
echo 'stopped and exited'
else
echo 'Docker already removed'
fi
I changed the parameter "-o" to "[ ] || [ ]" after being informed by tjm3772 that the "-o" option is obsolete in POSIX 2017.
Answered By - cforler Answer Checked By - Dawn Plyler (WPSolving Volunteer)