Issue
I'm working on a script that checks (with If statements) if a variable contains a specific character. If a character is found the script executes some code. If a certain character cannot be found, the script will go into another If Statement to check if the variable contains another specific character, and so on.
this all works perfectly fine.
But I need the script to tell me if none of the characters are found, but i'm having some trouble accomplishing this goal. the script looks like this.
if [[ "$results" == *"specific character"* ]]; then
do something.
fi
if [[ "$results" == *"specific character"* ]]; then
do something.
fi
if [[ "$results" == *"specific character"* ]]; then
do something.
fi
If all these If Statements cannot find their character I need the script to echo that these characters are not found.
I tried to put a If/else statement around all the other If statements, but this did not work for me.
if [[ ]]; then
if [[ "$results" == *"specific character"* ]]; then
do something.
fi
if [[ "$results" == *"specific character"* ]]; then
do something.
fi
if [[ "$results" == *"specific character"* ]]; then
do something.
fi
else
echo "characters are not found."
I can't seem to get it to work. Can somebody give me a push in the right direction?
Kind Regards,
Sleek
Solution
Use a case
statement:
case "$results" in
*c*) do something;;
*d*) do something;;
*e*|*f*) do something
do another thing;;
*) echo "characters are not found.";;
esac
Answered By - Dennis Williamson Answer Checked By - Marilyn (WPSolving Volunteer)