#!/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
上述脚本的目的是当脚本像这样运行时抛出(自定义)错误:
./myscript.sh Alice
即显示错误如下:
"Usage: error_handling.sh Alice"
但如果同样的脚本像这样运行:
./myscript.sh "Alice"
它应该显示:
Hello, Alice
但是它会针对这两种情况抛出自定义错误语句。
如何解决此问题?