M HYPE SPLASH
// general

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"
fi

The intention of the above script is to throw (custom) error when script is run like this:

./myscript.sh Alice

i.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, Alice

But it throws the custom error statement for both the conditions.

How can this be resolved?

3 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy