![传递参数时不带双引号时抛出错误](https://linux22.com/image/1017297/%E4%BC%A0%E9%80%92%E5%8F%82%E6%95%B0%E6%97%B6%E4%B8%8D%E5%B8%A6%E5%8F%8C%E5%BC%95%E5%8F%B7%E6%97%B6%E6%8A%9B%E5%87%BA%E9%94%99%E8%AF%AF.png)
#!/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
但是它会针对这两种情况抛出自定义错误语句。
如何解决此问题?