#!/bin/sh if [ "$#" -ne 1 ] || ! [ -d "$1" ]; then echo "Usage: $0 DIRECTORY" >&2 exit 1 fi
翻译:如果参数数量(数字)不等于1或第一个参数不是目录,则将使用情况输出到stderr并退出并返回失败状态代码。
更友好的错误报告:
#!/bin/sh if [ "$#" -ne 1 ]; then echo "Usage: $0 DIRECTORY" >&2 exit 1 fi if ! [ -e "$1" ]; then echo "$1 not found" >&2 exit 1 fi if ! [ -d "$1" ]; then echo "$1 not a directory" >&2 exit 1 fi