我想用一个更干净,更难看的单线来完成测试:
#!/bin/bash test -d "$1" || (echo "Argument 1: '$1' is not a directory" 1>&2 ; exit 1) || exit 1 # ... script continues if $1 is directory...
基本上我是在一些不复制出口的东西之后,最好不会产生一个子壳(因此看起来也应该看起来不那么难看),但仍然适合一行.
没有子shell而没有重复退出:
test -d "$1" || { echo "Argument 1: '$1' is not a directory" 1>&2 ; exit 1; }
您可能还想参考Grouping Commands:
{}
06001
Placing a list of commands between curly braces causes the list to be executed in the current shell context. No subshell is created. The semicolon (or newline) following list is required.