📄 func.tests
字号:
a(){ x=$((x - 1)) return 5}b(){ x=$((x - 1)) a echo a returns $? return 4}c(){ x=$((x - 1)) b echo b returns $? return 3}d(){ x=$((x - 1)) c echo c returns $? return 2}e(){ d echo d returns $? echo in e x=$((x - 1)) return $x}f(){ e echo e returned $? echo x is $x return 0}x=30f# make sure unsetting a local variable preserves the `local' attributef1(){ local zz zz=abcde echo $zz unset zz zz=defghi echo $zz}zz=ZZecho $zzf1echo $zzunset -f f1f1(){ return 5}( f1 )echo $?unset -f f1f1(){ sleep 5 return 5}f1 &waitecho $?unset -f f1f1(){ echo $AVAR printenv AVAR}AVAR=AVARecho $AVARf1AVAR=foo f1echo $AVARunset -f f1# make sure subshells can do a `return' if we're executing in a functionf1(){ ( return 5 ) status=$? echo $status return $status}f1echo $?declare -F f1 # should print just the namedeclare -f f1 # should print the definition, too# no functions should be exported, right?declare -xFdeclare -xf# FUNCNAME testsfunc2(){ echo FUNCNAME = $FUNCNAME}func(){ echo before: FUNCNAME = $FUNCNAME func2 echo after: FUNCNAME = $FUNCNAME}echo before: try to assign to FUNCNAMEFUNCNAME=7echo outside: FUNCNAME = $FUNCNAMEfuncecho outside2: FUNCNAME = $FUNCNAME# test exported functions (and cached exportstr)zf(){ echo this is zf}export -f zf${THIS_SH} -c 'type -t zf'${THIS_SH} -c 'type zf'${THIS_SH} ./func1.sub# tests for functions whose bodies are not group commands, with and without# attached redirections${THIS_SH} ./func2.sub# test for some posix-specific function behavior${THIS_SH} ./func3.sub# FUNCNEST testing${THIS_SH} ./func4.subunset -f myfunctionmyfunction() { echo "bad shell function redirection"} >> /dev/nullmyfunctionmyfunction | catsegv(){ echo foo | return 5}segvecho $?exit 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -