ZERO=0
if[ $ZERO -eq 0 ];thenecho$ZERO;fiif test $ZERO -eq 0;thenecho$ZERO;fi
test $ZERO -eq 0 && echo$ZERO# if return true
test $ZERO -eq 0 || echo$ZERO# if return false[ $ZERO -eq 0] && {
echo $ZERO # if return true
}
getopts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
OPTINT=1while getopts lf:h ARGS; do
case $ARGS in
l)
...
;;
f)
FILE=$OPTARG # 如果选项后跟着冒号,表示选项后跟的是参数...
;;
h)
...
;;
*)
usage
;;
esac
done
noclobber
The setting shell parameter set -o noclobber (bash, ksh) will prevent > from clobbering by making it issue an error message instead:
1
2
3
4
5
6
7
8
echo "Hello, world" >file.txt
echo "This will overwrite the first greeting." >file.txt
set -o noclobber
echo "Can we overwrite it again?" >file.txt
-bash: file.txt: cannot overwrite existing file
echo "But we can use the >| operator to ignore the noclobber." >|file.txt
# Successfully overwrote the contents of file.txt using the >| operatorset +o noclobber # Changes setting back