To throw error when arguments are passed without double quotes
By Emma Valentine •
#!/usr/bin/env bash
#myscript.sh
if [[ "$1" == "" ]]
then echo "Hello, "
elif ! [[ "$1" =~ "*[a-z]*[A-z]" ]]
then echo "Usage: error_handling.sh $1"
elif [[ "$1" != "" ]]
then echo "Hello, $1"
else echo "Usage: error_handling.sh $1"
fiThe intention of the above script is to throw (custom) error when script is run like this:
./myscript.sh Alicei.e. it shows error as:
"Usage: error_handling.sh Alice"But if the same script is run like this:
./myscript.sh "Alice"it should show:
Hello, AliceBut it throws the custom error statement for both the conditions.
How can this be resolved?
3 Reset to default