我正在尝试验证用户对我正在编写的一个小脚本的输入,该脚本检查是否应该有:2 个参数,第一个参数应该是“mount”或“unmount”
我有以下内容:
if [ ! $# == 2 ] || [ $1 != "mount" -o $1 != "unmount" ]; then
然而,在满足我想要的条件时似乎有点过分。例如与当前 || 运算符,没有任何东西可以通过验证器,但是如果我使用 && 运算符,一切都可以。
if [ ! $# == 2 ] && [ $1 != "mount" -o $1 != "unmount" ]; then
有人可以帮我解决这个问题吗?
这是整个块和预期用途
if [ ! $# == 2 ] || [ $1 != "mount" -o $1 != "unmount" ]; then
echo "Usage:"
echo "encmount.sh mount remotepoint # mount the remote file system"
echo "encmount.sh unmount remotepoint # unmount the remote file system"
exit
fi