?? builtins.tests
字號:
# tests for miscellaneous builtins not tested elsewhereset +pset +o posixulimit -c 0 2>/dev/null# check that break breaks loopsfor i in a b c; do echo $i; break; echo bad-$i; doneecho end-1for i in a b c; do echo $i; break 1; echo bad-$i; doneecho end-2for i in a b c; do for j in x y z; do echo $i:$j break echo bad-$i done echo end-$idoneecho end-3# check that break breaks nested loopsfor i in a b c; do for j in x y z; do echo $i:$j break 2 echo bad-$i done echo end-$idoneecho end# check that continue continues loopsfor i in a b c; do echo $i; continue; echo bad-$i ; doneecho end-1for i in a b c; do echo $i; continue 1; echo bad-$i; doneecho end-2for i in a b c; do for j in x y z; do echo $i:$j continue echo bad-$i-$j done echo end-$idoneecho end-3# check that continue breaks out of nested loopsfor i in a b c; do for j in x y z; do echo $i:$j continue 2 echo bad-$i-$j done echo end-$idoneecho end# check that `eval' re-evaluates arguments, but `builtin' and `command' do notAVAR='$BVAR'BVAR=fooecho $AVARbuiltin echo $AVARcommand echo $AVAReval echo \$AVAReval echo $AVAR# test out eval with a temp environmentAVAR=bar eval echo \$AVARBVAR=xxx eval echo $AVARunset -v AVAR BVAR# test umaskmask=$(umask)umask 022umaskumask -Sumask -S u=rwx,g=rwx,o=rx >/dev/null # 002umaskumask -Sumask -pumask -p -Sumask 0umask -Sumask ${mask} # restore original mask# builtin/command without arguments should do nothing. maybe someday they willbuiltincommand# test enableenable -psenable -aps ; enable -npsenable -n testcase "$(type -t test)" inbuiltin) echo oops -- enable -n test failed ;;*) echo enable -n test worked ;;esacenable testcase "$(type -t test)" inbuiltin) echo enable test worked ;;*) echo oops -- enable test failed ;;esac# test options to exec(exec -a specialname ${THIS_SH} -c 'echo $0' )(exec -l -a specialname ${THIS_SH} -c 'echo $0' )# test `clean' environment. if /bin/sh is bash, and the script version of# printenv is run, there will be variables in the environment that bash# sets on startup. Also test code that prefixes argv[0] with a dash.(export FOO=BAR ; exec -c -l printenv ) | grep FOO(FOO=BAR exec -c printenv ) | grep FOO(export FOO=BAR ; exec printenv ) | grep FOO(FOO=BAR exec printenv ) | grep FOO# ok, forget everything about hashed commandshash -rhash# this had better succeed, since command -p guarantees we will find the# standard utiltiescommand -p hash rm# check out source/.# sourcing a zero-length-file had better not be an errorrm -f /tmp/zero-length-filecp /dev/null /tmp/zero-length-file. /tmp/zero-length-fileecho $?rm /tmp/zero-length-fileAVAR=AVAR. ./source1.subAVAR=foo . ./source1.sub. ./source2.subecho $?set -- a b c. ./source3.sub# make sure source with arguments does not change the shell's positional# parameters, but that the sourced file sees the arguments as its# positional parametersecho "$@". ./source3.sub x y zecho "$@"# but if the sourced script sets the positional parameters explicitly, they# should be reflected in the calling shell's positional parameters. this# also tests one of the shopt options that controls source using $PATH to# find the scriptecho "$@"shopt -u sourcepath. source4.subecho "$@"# this is complicated when the sourced scripts gets its own positional# parameters from arguments to `.'set -- a b cecho "$@". source4.sub x y zecho "$@"# test out cd and $CDPATH${THIS_SH} ./builtins1.sub# test behavior of `.' when given a non-existant file argument${THIS_SH} ./source5.sub# test bugs in sourcing non-regular files, fixed post-bash-3.2${THIS_SH} ./source6.sub# in posix mode, assignment statements preceding special builtins are# reflected in the shell environment. `.' and `eval' need special-case# code.set -o posixecho $AVARAVAR=foo . ./source1.subecho $AVARAVAR=AVARecho $AVARAVAR=foo eval echo \$AVARecho $AVARAVAR=AVARecho $AVARAVAR=foo :echo $AVARset +o posix# but assignment statements preceding `export' are always reflected in # the environmentfoo="" export foodeclare -p foounset foo# assignment statements preceding `declare' should be displayed correctly,# but not persist after the commandFOO='$$' declare -p FOOdeclare -p FOOunset FOO# except for `declare -x', which should be equivalent to `export'FOO='$$' declare -x FOOdeclare -p FOOunset FOO# test out kill -l. bash versions prior to 2.01 did `kill -l num' wrongsigone=$(kill -l | sed -n 's:^ 1) *\([^ ]*\)[ ].*$:\1:p')case "$(kill -l 1)" in${sigone/SIG/}) echo ok;;*) echo oops -- kill -l failure;;esac# kill -l and trap -l should display exactly the same outputsigonea=$(trap -l | sed -n 's:^ 1) *\([^ ]*\)[ ].*$:\1:p')if [ "$sigone" != "$sigonea" ]; then echo oops -- kill -l and trap -l differfi# POSIX.2 says that exit statuses > 128 are mapped to signal names by# subtracting 128 so you can find out what signal killed a processcase "$(kill -l $(( 128 + 1)) )" in${sigone/SIG/}) echo ok;;*) echo oops -- kill -l 129 failure;;esac# out-of-range signal numbers should report the argument in the error# message, not 128 less than the argumentkill -l 4096# kill -l NAME should return the signal numberkill -l ${sigone/SIG/}# test behavior of shopt xpg_echo${THIS_SH} ./builtins2.sub# test behavior of declare -g${THIS_SH} ./builtins3.sub# this must be last -- it is a fatal errorexit statusecho after bad exit
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -