⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 new-exp.tests

📁 android-w.song.android.widget
💻 TESTS
字号:
# must do this because posix mode causes process substitution to be disabled# and flagged as a syntax error, which causes the shell to exitset +o posixexpect(){        echo expect "$@"}HOME=/usr/homes/chet	# to make the check against new-exp.right workexpect '<foo bar>'recho "${undef-"foo bar"}"	# should be foo barexpect '<foo>'recho "${und="foo"}"		# should be fooexpect "<$HOME>"recho ${HOME-"}"}expect "<$HOME>"recho "${HOME-'}'}"expect "<$HOME>"recho "${HOME-"}"}"expect $0: 'HOME: }: syntax error: operand expected (error token is "}")'recho "${HOME:`echo }`}"	# should be a math error -- bad substring substitutionexpect unset_ENV=oopsx=${_ENV[(_$-=0)+(_=1)-_${-%%*i*}]}echo ${x:-unset}expect "<$HOME>"recho ${HOME}expect "<$HOME>"recho ${HOME:-`echo }`}expect "<$HOME>"recho ${HOME:-`echo "}"`}expect "<$HOME>"recho "${HOME:-`echo "}"`}"expect "<$HOME>"recho "$(echo "${HOME}")"expect "<$HOME>"recho "$(echo "$(echo ${HOME})")"expect "<$HOME>"recho "$(echo "$(echo "${HOME}")")"P=*@*expect '<*@>'recho "${P%"*"}"	# expect '<*@>'recho "${P%'*'}"	# expect '<@*>'recho "${P#\*}"		# should be @*expect '<)>'recho "$(echo ")")"	# should be )expect '<")">'recho "$(echo "\")\"")"	# should be ")"foo='abcd   'expect '<-abcd> <->'recho -${foo}-		# should be -abcd -expect '<-abcd> <->'recho -${foo% *}-	# should be -abcd -expect '<-abcd->'recho -${foo%% *}-	# should be -abcd-foo=barexpect '<bar foo>'echo -n $foo' ' ; echo fooexpect '<bar foo>'echo -n $foo" " ; echo fooexpect '<bar foo>'echo -n "$foo " ; echo fooexpect '<barfoo>'echo -e "$foo\c " ; echo fooexpect '<barfoo>'echo -e $foo"\c " ; echo foo# make sure backslashes are preserved in front of characters that are not# valid backslash escapesexpect '<\x>'echo -e '\x'# substring testsz=abcdefghijklmnopexpect '<abcd>'recho ${z:0:4}expect '<efg> <nop>'recho ${z:4:3} ${z:${#z}-3:3}expect '<efg> <nop>'recho ${z:4:3} ${z: -3:3}expect '<hijklmnop>'recho ${z:7:30}expect '<abcdefghijklmnop>'recho ${z:0:100}expect '<abcdefghijklmnop>'recho ${z:0:${#z}}set 'ab cd' 'ef' 'gh ij' 'kl mn' 'op'expect '<ab cd> <ef>'recho "${@:1:2}"expect '<gh ij> <kl mn>'recho "${@:3:2}"expect '<gh ij> <kl mn> <op>'recho "${@:3:4}"expect '<ab cd> <ef> <gh ij> <kl mn> <op>'recho "${@:1:$#}"# code to ad-hoc parse arithmetic expressions in substring expansions was# broken until post-2.04base=/home/chet/foo//barstring1=$base/abcabcabcx=1 j=4expect '</home/chet/foo//bar/abcabcabc>'recho ${string1:0}expect '<home/chet/foo//bar/abcabcabc>'recho ${string1:1}expect '<home>'recho ${string1:(j?1:0):j}expect '<home>'recho ${string1:j?1:0:j}expect '<home>'recho ${string1:(j?(x?1:0):0):j}expect '<home>'recho ${string1:j?(x?1:0):0:j}unset base string1 x j# indirect variable referencesexpect '<abcdefghijklmnop>'recho ${!9:-$z}ef=4expect '<4>'recho ${!2}expect '<op>'recho ${!#}set a b c d ea=expect '<abcdefghijklmnop>'recho ${a:-$z}expect '<abcdefghijklmnop>'recho ${!1:-$z}expect nothingrecho ${a-$z}expect nothingrecho ${!1-$z}set -uexpect $0: ABX: unbound variable( recho ${ABX} )set +uexpect $0: '$6: cannot assign in this way'recho ${6="arg6"}v=abcde# sed-like variable substitutionexpect '<xxcde>'recho ${v/a[a-z]/xx}expect '<axxde>'recho ${v/a??/axx}expect '<abxyz>'recho ${v/c??/xyz}expect '<abbcde>'recho ${v/#a/ab}expect '<abcde>'recho ${v/#d/ab}expect '<abcabe>'recho ${v/d/ab}expect '<abcdlast>'recho ${v/%?/last}expect '<abcde>'recho ${v/%x/last}av=(abcd efgh ijkl mnop qrst uvwx)expect '<xxcd>'recho ${av/??/xx}expect '<abxx>'recho ${av/%??/xx}expect '<xxgh>'recho ${av[1]/??/xx}expect '<efgh>'recho ${av[1]/%ab/xx}expect '<xxfgh>'recho ${av[1]/#?/xx}expect '<zagh>'recho ${av[1]/??/za}expect '<zaza>'recho ${av[1]//??/za}expect '<zagh>'recho ${av[1]/#??/za}expect '<efza>'recho ${av[1]/%??/za}expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'recho ${av[@]/*/yyy}expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'recho ${av[@]/#*/yyy}expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'recho ${av[@]/%*/yyy}expect '<yyy> <efgh> <ijkl> <mnop> <qrst> <uvwx>'recho ${av[@]/a*/yyy}expect '<abxx> <efxx> <ijxx> <mnxx> <qrxx> <uvxx>'recho ${av[@]/%??/xx}set abcd efgh ijkl mnop qrst uvwxexpect '<xxcd>'recho ${1/??/xx}expect '<xxcd> <xxgh> <xxkl> <xxop> <xxst> <xxwx>'recho ${@/??/xx}expect '<xxcd> <xxgh> <xxkl> <xxop> <xxst> <xxwx>'recho ${@/%??/xx}expect '<zaza>'recho ${3//??/za}expect '<efza>'recho ${3/%??/za}expect '<zaza> <zaza> <zaza> <zaza> <zaza> <zaza>'recho ${@//??/za}expect '<zacd> <zagh> <zakl> <zaop> <zast> <zawx>'recho ${@/#??/za}expect '<yyy> <yyy> <yyy> <yyy> <yyy> <yyy>'recho ${@//*/yyy}expect '<yyy> <efgh> <ijkl> <mnop> <qrst> <uvwx>'recho ${@//a*/yyy}expect '<abcd> <efgh> <ijkl> <mnop> <qrst> <uvwyyy>'recho ${@/%x*/yyy}expect a newlineecho $abmcde# sneaky way to replace a newline in a variable value with something elseAVAR=$'This\nstring\nhas\nmultiple\nlines.'echo "${AVAR}"eval BVAR=\"\${AVAR//$'\n'/-}\"echo "$BVAR"unset AVAR BVAR# run process substitution tests in a subshell so that syntax errors# caused by a shell not implementing process substitution (e.g., one# built on a NeXT) will not cause the whole test to exit prematurely${THIS_SH} ./new-exp1.sub# run the tests of $(<filename) in a subshell to avoid cluttering up# this script${THIS_SH} ./new-exp2.subexpect '<6>'recho ${#:-foo}expect $0: '${#:}: bad substitution'echo ${#:}expect "<'>"recho "'"expect '<">'recho '"'expect '<"hello">'recho "\"hello\""shift $#unset fooz=abcdefz1='abc def'expect '<>'recho ${foo:-""}expect nothingrecho ${foo:-"$@"}expect '<>'recho "${foo:-$@}"# unset varexpect '<>'recho ${foo:-"$zbcd"}expect nothingrecho ${foo:-$zbcd}# set varexpect '<abcdef>'recho ${foo:-"$z"}expect '<abc def>'recho ${foo:-"$z1"}expect '<abcdef>'recho ${foo:-$z}expect '<abc> <def>'recho ${foo:-$z1}expect '<abcdef>'recho "${foo:-$z}"expect '<abc def>'recho "${foo:-$z1}"expect '<abcdef>'recho "${foo:-"$z"}"# this disagrees with sh and ksh, but I think it is right according# to posix.2.expect '<abc def>'recho "${foo:-"$z1"}"set ab cd ef ghexpect '<ab> <cd> <ef> <gh>'recho ${foo:-"$@"}expect '<ab> <cd> <ef> <gh>'recho "${foo:-$@}"expect '<ab> <cd> <ef> <gh>'recho "${foo:-"$@"}"shift $#expect nothingrecho $xxx"$@"expect nothingrecho ${foo:-$xxx"$@"}expect '<>'recho "${foo:-$xxx$@}"expect '<>'recho "${foo:-$xxx"$@"}"expect nothingrecho $xxx"$@"expect nothingrecho "$xxx$@"expect nothingrecho "$@"$xxxexpect '<>'recho $xxx""expect '<>'recho $xxx''expect '<>'recho ''$xxxexpect '<>'recho ""$xxxAB='abcdefghijklmnopqrstuvwxyz'recho ${AB:7:15}recho ${AB:15:7}recho ${AB:20}recho ${AB:0}recho ${AB:0:20}recho ${AB:10:7}recho ${AB:10:3+4}recho ${AB:20/2:3+4}set 1 2 3 4 5 6recho \""${*:2:2}"\"IFS=:recho \""${*:2:2}"\"IFS=$' \t\n'z=123456recho \""${z:2:2}"\"recho \""${z:2}"\"recho \""${z:2:4}"\"recho \""${z:2:6}"\"set $'\1' $'\2' $'\177'recho $*recho $@recho ${*}recho ${@}xx=one/two/tworecho ${xx%/*}recho ${xx/\/two}yy=oneonetworecho ${yy//one}recho ${yy/\/one}xx=oneonetworecho ${xx/one}recho ${xx//one}recho ${xx/\/one}# out-of-range substringsvar=abcc=${var:3}expect nothingrecho $cc=${var:4}expect nothingrecho $c# as of bash-4.2, negative LENGTH means offset from the endc=${var:0:-2}expect '<a>'recho $cvar=abcdefghic=${var:3:12}recho $cc=${var:4:20}recho $c# make sure null patterns workxxx=endocrineyyy=nunset zzzrecho ${xxx/$yyy/*}recho ${xxx//$yyy/*}recho ${xxx/$zzz/*}recho ${xxx//$zzz/*}recho ${xxx//%${zzz}/}recho ${xxx//%${zzz}}recho ${xxx//#${zzz}/}recho ${xxx//#${zzz}}# another case that caused a core dump in bash-2.0XPATH=/usr/bin:/bin:/usr/local/bin:/usr/gnu/bin::/usr/bin/X11:/sbin:/usr/sbinrecho ${XPATH//:/ }xx=(ar as at au av aw ax ay az)recho ${xx[@]/a/}recho ${xx[@]//a/}recho ${xx[*]/a/}recho ${xx[*]//a/}recho ${xx[@]%?}recho ${xx[*]%?}recho ${xx[@]#?}recho ${xx[*]#?}set -- ar as at au av aw ax ay azrecho ${@/a/}recho ${@//a/}recho ${*/a/}recho ${*//a/}recho ${@%?}recho ${*%?}recho ${@#?}recho ${*#?}shift $#set -u( recho $9 ; echo after 1)( recho ${9} ; echo after 2)( recho $UNSET ; echo after 3)( recho ${UNSET} ; echo after 4)( recho "$UNSET" ; echo after 5)( recho "${UNSET}" ; echo after 6)( recho "${#UNSET}" ; echo after 7)set +uRECEIVED="12345"recho "${RECEIVED:$((${#RECEIVED}-1)):1}"RECEIVED="12345#"recho "${RECEIVED:$((${#RECEIVED}-1)):1}"RECEIVED="#"recho "${RECEIVED:$((${#RECEIVED}-1)):1}"RECEIVED=""recho "${RECEIVED:$((${#RECEIVED}-1)):1}"# tests of new prefix expansion ${!prefix*}${THIS_SH} ./new-exp3.sub# bug with indirect expansion through bash-2.05b${THIS_SH} ./new-exp4.sub# these caused errors and core dumps in versions before bash-2.04c=""echo ${c//${$(($#-1))}/x/}set a b c d e f grecho "$@"set -- ${@:1:$(($# - 2))}recho "$@"set a brecho ${@:1:$(($# - 2))}recho ${@:1:0}recho ${@:1:1}recho ${@:1:2}recho "${*:1:0}"# this is an error -- negative expressionset arecho ${@:1:$(($# - 2))}XPATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:.:/sbin:/usr/sbinset $( IFS=: ; echo $XPATH ) recho ${@##*/}recho ${@%%[!/]*}recho ${@#/*}recho ${@%*/}set /full/path/to/x16 /another/full/pathrecho ${1%/*}recho ${1%%[!/]*}recho ${1#*/}recho ${1##*/}${THIS_SH} ./new-exp5.subunset varvar=blah# these had better agreeecho ${var[@]:3}echo ${var:3}echo ${var[@]/#/--}echo ${var/#/--}echo ${var[@]##?}echo ${var##?}unset varvar=(abcde abcfg abchi)# problems with anchoring pattern replacementsecho ${var[*]//#abc/foo}echo ${var[*]/#abc/foo}unset var${THIS_SH} ./new-exp6.sub${THIS_SH} ./new-exp7.sub${THIS_SH} ./new-exp8.sub# problems with stray CTLNUL in bash-4.0-alphaunset aa=/arecho "/${a%/*}"recho "/${a///a/}"# this must be last!expect $0: 'ABXD: parameter unset'recho ${ABXD:?"parameter unset"}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -