├── .gitignore ├── ChangeLog ├── tests ├── redir4.in1 ├── parser.right ├── exec1.sub ├── redir3.in1 ├── source1.sub ├── source3.sub ├── redir3.in2 ├── source4.sub ├── comsub-eof2.sub ├── exec8.sub ├── redir2.sub ├── array1.sub ├── parser1.sub ├── ifs-posix.right ├── misc │ ├── run-r2.sh │ ├── sigint-2.sh │ ├── sigint-3.sh │ ├── sigint-1.sh │ ├── sigint-4.sh │ ├── test-minus-e.1 │ ├── test-minus-e.2 │ ├── redir-t2.sh │ ├── perftest │ ├── read-nchars.tests │ ├── dev-tcp.tests │ └── wait-bg.tests ├── comsub-eof3.sub ├── comsub-eof0.sub ├── comsub-eof1.sub ├── comsub-eof4.sub ├── input-line.sub ├── comsub-posix1.sub ├── read4.sub ├── README ├── array.right ├── set-e3a.sub ├── invert.right ├── nquote4.right ├── array2.sub ├── redir6.sub ├── trap2a.sub ├── errors2.sub ├── exec4.sub ├── comsub-eof5.sub ├── exec3.sub ├── run-case ├── run-ifs ├── run-rsh ├── run-set-e ├── run-strip ├── run-tilde ├── run-type ├── heredoc2.sub ├── history.list ├── run-alias ├── run-arith ├── run-braces ├── run-iquote ├── run-precedence ├── run-quote ├── run-shopt ├── run-tilde2 ├── source2.sub ├── nquote1.sub ├── run-casemod ├── run-comsub ├── run-coproc ├── run-cprint ├── run-dollars ├── run-getopts ├── run-herestr ├── run-input-test ├── run-mapfile ├── run-parser ├── run-posixpat ├── run-rhs-exp ├── run-vredir ├── trap1.sub ├── extglob2.sub ├── run-appendop ├── run-arith-for ├── run-ifs-posix ├── run-lastpipe ├── run-posixexp ├── run-posixexp2 ├── run-posixpipe ├── exec2.sub ├── run-attr ├── run-comsub-eof ├── run-exportfunc ├── dollar-at3.sub ├── dollar-star4.sub ├── run-comsub-posix ├── run-exp-tests ├── run-varenv ├── coproc.right ├── input.right ├── nameref9.sub ├── run-invert ├── run-nquote ├── run-nquote5 ├── run-posix2 ├── ifs.right ├── run-more-exp ├── type1.sub ├── arith4.sub ├── input-line.sh ├── redir12.sub ├── run-test ├── trap3.sub ├── dbg-support2.right ├── lastpipe1.sub ├── run-extglob3 ├── array3.sub ├── dollar-at4.sub ├── run-globstar ├── vredir3.sub ├── nameref2.sub ├── strip.right ├── errors5.sub ├── mapfile2.sub ├── parser.tests ├── run-errors ├── run-extglob ├── run-extglob2 ├── run-glob-test ├── redir1.sub ├── vredir1.sub ├── exp4.sub ├── getopts9.sub ├── type2.sub ├── heredoc1.sub ├── assoc8.sub ├── version ├── nquote3.sub ├── histexp2.sub ├── printf2.sub ├── version.mini ├── builtins2.sub ├── dollar-star5.sub ├── exp3.sub ├── getopts8.sub ├── jobs5.sub ├── comsub2.sub ├── history2.sub ├── new-exp7.sub ├── builtins1.sub ├── builtins3.sub ├── dollar-at2.sub ├── unicode3.sub ├── exp7.sub ├── intl1.sub ├── run-assoc ├── run-dirstack ├── arith7.sub ├── comsub-eof.tests ├── history1.sub ├── run-array2 ├── run-history ├── run-nameref ├── vredir6.sub ├── alias.right ├── nameref7.sub ├── run-histexpand ├── run-read ├── new-exp1.sub ├── comsub-posix3.sub ├── intl2.sub ├── read6.sub ├── set-e3.sub ├── glob1.sub ├── run-nquote1 ├── run-nquote2 ├── run-nquote3 ├── type3.sub ├── errors3.sub ├── nameref1.sub ├── run-nquote4 ├── test-glue-functions ├── assoc3.sub ├── jobs2.sub ├── appendop1.sub ├── lastpipe.right ├── errors1.sub ├── exec5.sub ├── getopts10.sub ├── vredir4.sub ├── dollar-star2.sub ├── mapfile1.sub ├── varenv5.sub ├── array13.sub ├── extglob3.sub ├── exportfunc1.sub ├── assoc1.sub ├── run-func ├── vredir5.sub ├── dollar-star6.sub ├── jobs1.sub ├── run-builtins ├── varenv8.sub ├── appendop2.sub ├── exp2.sub ├── extglob1a.sub ├── vredir7.sub ├── attr2.sub ├── assoc7.sub ├── run-trap ├── case.right ├── exec9.sub ├── histexp4.sub ├── run-heredoc ├── assoc2.sub ├── read1.sub ├── dollar-star3.sub ├── globstar1.sub ├── histexp1.sub ├── redir3.sub ├── array7.sub ├── extglob3.right ├── run-intl ├── run-set-x ├── alias2.sub ├── run-jobs ├── exec11.sub ├── run-array ├── run-dbg-support ├── trap2.sub ├── alias1.sub ├── run-printf ├── source5.sub ├── run-cond ├── set-x.tests ├── exec12.sub ├── posix2.right ├── array9.sub ├── COPYRIGHT ├── dollar-at-star8.sub ├── func2.sub ├── set-x1.sub ├── tilde2.right ├── assoc4.sub ├── exp5.sub ├── read3.sub ├── array8.sub ├── mapfile.data ├── redir10.sub ├── dollar-at-star1.sub ├── herestr1.sub ├── varenv6.sub ├── dollar-at1.sub ├── dstack2.right ├── redir5.sub ├── nquote4.tests ├── posixpat.right ├── dollar-at-star6.sub ├── posixpipe.right ├── errors4.sub ├── exportfunc3.sub ├── exec13.sub ├── new-exp3.sub ├── run-redir ├── strip.tests ├── tilde.right ├── array15.sub ├── dollar-at-star7.sub ├── dollar-star1.sub ├── getopts1.sub ├── jobs4.sub ├── read2.sub ├── dollar-at6.sub ├── jobs3.sub ├── trap5.sub ├── array14.sub ├── invert.tests ├── run-dbg-support2 ├── comsub-posix2.sub ├── exp1.sub ├── varenv3.sub ├── varenv1.sub ├── assoc5.sub ├── intl3.sub ├── array12.sub ├── array5.sub ├── histexp3.sub ├── type4.sub ├── getopts6.sub ├── exec7.sub ├── new-exp6.sub ├── read5.sub ├── varenv2.sub ├── dbg-support2.tests ├── set-e2.sub ├── array16.sub ├── extglob4.sub ├── array4.sub ├── errors6.sub ├── func4.sub ├── posixpipe.tests ├── exportfunc.right ├── comsub3.sub ├── exp8.sub ├── getopts2.sub ├── getopts3.sub ├── array18.sub ├── herestr.right ├── herestr.tests ├── arith1.sub ├── appendop.right ├── redir9.sub ├── lastpipe2.sub ├── run-new-exp ├── new-exp9.sub ├── array21.sub ├── run-execscript ├── dbg-support3.sub ├── getopts4.sub ├── getopts7.sub ├── array11.sub ├── builtins4.sub ├── dstack2.tests ├── arith2.sub ├── nquote2.sub ├── rsh.tests ├── vredir.tests ├── vredir2.sub ├── attr.tests ├── extglob1.sub ├── rsh.right ├── comsub-eof.right ├── source6.sub ├── new-exp5.sub ├── posixexp2.right ├── dbg-support.sub ├── alias.tests ├── nameref6.sub ├── comsub.right ├── set-x.right ├── dollar-at-star3.sub ├── dollar-star7.sub ├── getopts5.sub ├── exp6.sub ├── nameref3.sub ├── varenv4.sub ├── cond-regexp2.sub ├── func3.sub ├── builtins6.sub ├── func1.sub ├── source7.sub ├── set-e.right ├── array20.sub ├── nameref8.sub ├── redir8.sub ├── attr1.sub ├── nameref18.sub ├── run-all ├── iquote1.sub ├── unicode2.sub ├── redir4.sub ├── redir11.sub ├── new-exp4.sub ├── nameref16.sub ├── arith6.sub ├── posixexp2.sub ├── prec.right ├── arith3.sub ├── ifs.tests ├── comsub1.sub └── intl.tests ├── lib ├── glob │ └── doc │ │ ├── glob.texi │ │ └── Makefile ├── intl │ ├── VERSION │ ├── locale.alias │ ├── ChangeLog │ └── osdep.c ├── readline │ ├── STANDALONE │ ├── doc │ │ └── version.texi │ └── README ├── tilde │ └── README ├── malloc │ ├── i386-alloca.s │ └── stub.c └── sh │ └── fmtumax.c ├── po ├── README ├── af.po ├── et.po ├── ro.po ├── af.gmo ├── bg.gmo ├── ca.gmo ├── cs.gmo ├── da.gmo ├── de.gmo ├── el.gmo ├── eo.gmo ├── es.gmo ├── et.gmo ├── fi.gmo ├── fr.gmo ├── ga.gmo ├── gl.gmo ├── hr.gmo ├── hu.gmo ├── id.gmo ├── it.gmo ├── ja.gmo ├── lt.gmo ├── nb.gmo ├── nl.gmo ├── pl.gmo ├── ro.gmo ├── ru.gmo ├── sk.gmo ├── sl.gmo ├── sr.gmo ├── sv.gmo ├── tr.gmo ├── uk.gmo ├── vi.gmo ├── pt_BR.gmo ├── zh_CN.gmo ├── zh_TW.gmo ├── en@quot.gmo ├── en@boldquot.gmo ├── quot.sed ├── LINGUAS ├── boldquot.sed ├── remove-potcdate.sin ├── Rules-builtins └── insert-header.sin ├── doc ├── bash.pdf ├── article.pdf ├── bashref.dvi ├── bashref.pdf ├── rose94.pdf ├── aosa-bash.pdf ├── aosa-bash-full.pdf ├── rbash.1 ├── infopost.sh ├── version.texi └── builtins.1 ├── CWRU ├── changelog ├── sh-redir-hack ├── PLATFORMS ├── README └── misc │ └── bison ├── examples ├── functions │ ├── shcat │ ├── login │ ├── inpath │ ├── shcat2 │ ├── fact │ ├── isvalidip │ ├── array-to-string │ ├── dirname │ ├── exitstat │ └── basename ├── complete │ └── bashcc-1.0.1.tar.gz ├── scripts │ ├── cat.sh │ └── inpath ├── loadables │ └── perl │ │ ├── README │ │ ├── iperl.c │ │ └── bperl.c └── startup-files │ ├── Bash_profile │ └── README ├── Y2K ├── MANIFEST.doc └── support ├── SYMLINKS ├── bash.pc.in └── printenv.sh /.gitignore: -------------------------------------------------------------------------------- 1 | -i 2 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | CWRU/changelog -------------------------------------------------------------------------------- /tests/redir4.in1: -------------------------------------------------------------------------------- 1 | aa 2 | -------------------------------------------------------------------------------- /tests/parser.right: -------------------------------------------------------------------------------- 1 | AAA 2 | -------------------------------------------------------------------------------- /tests/exec1.sub: -------------------------------------------------------------------------------- 1 | echo "$@" 2 | -------------------------------------------------------------------------------- /tests/redir3.in1: -------------------------------------------------------------------------------- 1 | ab 2 | cd 3 | -------------------------------------------------------------------------------- /tests/source1.sub: -------------------------------------------------------------------------------- 1 | echo $AVAR 2 | -------------------------------------------------------------------------------- /tests/source3.sub: -------------------------------------------------------------------------------- 1 | echo "$@" 2 | -------------------------------------------------------------------------------- /tests/redir3.in2: -------------------------------------------------------------------------------- 1 | root 2 | daemon 3 | -------------------------------------------------------------------------------- /tests/source4.sub: -------------------------------------------------------------------------------- 1 | set -- m n o p 2 | -------------------------------------------------------------------------------- /tests/comsub-eof2.sub: -------------------------------------------------------------------------------- 1 | cat <&- 4 | pwd 5 | pwd 6 | echo $? 7 | echo $? 8 | echo $? 9 | -------------------------------------------------------------------------------- /tests/trap2a.sub: -------------------------------------------------------------------------------- 1 | echo before false in trap2a.sub 2 | false 3 | echo after false in trap2a.sub 4 | -------------------------------------------------------------------------------- /lib/intl/ChangeLog: -------------------------------------------------------------------------------- 1 | 2003-05-22 GNU 2 | 3 | * Version 0.12.1 released. 4 | 5 | -------------------------------------------------------------------------------- /examples/functions/shcat: -------------------------------------------------------------------------------- 1 | shcat() 2 | { 3 | while read -r line 4 | do 5 | echo "$line" 6 | done 7 | } 8 | -------------------------------------------------------------------------------- /tests/errors2.sub: -------------------------------------------------------------------------------- 1 | set -e 2 | trap 'echo $?' EXIT 3 | echo ${$NO_SUCH_VAR} # Bad substitution expected here 4 | -------------------------------------------------------------------------------- /tests/exec4.sub: -------------------------------------------------------------------------------- 1 | # let's test out the noexec code 2 | set -n 3 | 4 | fail 5 | whoops 6 | wow 7 | 8 | set +n 9 | -------------------------------------------------------------------------------- /tests/misc/sigint-2.sh: -------------------------------------------------------------------------------- 1 | echo before loop 2 | 3 | for i in 1 2 3 4 | do 5 | echo $i 6 | sleep 5 7 | done 8 | -------------------------------------------------------------------------------- /tests/comsub-eof5.sub: -------------------------------------------------------------------------------- 1 | echo $( 2 | cat <<\) 3 | hi 4 | )) 5 | 6 | echo $( 7 | cat <<\EOF 8 | hi 9 | EOF) 10 | -------------------------------------------------------------------------------- /tests/exec3.sub: -------------------------------------------------------------------------------- 1 | shopt -s execfail 2 | 3 | exec /tmp/bash-notthere 4 | # make sure we're still around 5 | echo $? 6 | 7 | -------------------------------------------------------------------------------- /tests/run-case: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./case.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} case.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-ifs: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./ifs.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} ifs.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-rsh: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./rsh.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} rsh.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-set-e: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./set-e.tests > ${BASH_TSTOUT} 2 | diff ${BASH_TSTOUT} set-e.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-strip: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./strip.tests > ${BASH_TSTOUT} 2 | diff ${BASH_TSTOUT} strip.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-tilde: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./tilde.tests > ${BASH_TSTOUT} 2 | diff ${BASH_TSTOUT} tilde.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-type: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./type.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} type.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /examples/complete/bashcc-1.0.1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gitGNU/gnu_bash/HEAD/examples/complete/bashcc-1.0.1.tar.gz -------------------------------------------------------------------------------- /tests/heredoc2.sub: -------------------------------------------------------------------------------- 1 | TEST=$(cat < ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} alias.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-arith: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./arith.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} arith.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-braces: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./braces.tests > ${BASH_TSTOUT} 2 | diff ${BASH_TSTOUT} braces.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-iquote: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./iquote.tests >${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} iquote.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-precedence: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./precedence > ${BASH_TSTOUT} 2 | diff ${BASH_TSTOUT} prec.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-quote: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./quote.tests >${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} quote.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-shopt: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./shopt.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} shopt.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-tilde2: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./tilde2.tests > ${BASH_TSTOUT} 2 | diff ${BASH_TSTOUT} tilde2.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/source2.sub: -------------------------------------------------------------------------------- 1 | echo in source.sub2, calling return 2 | 3 | return 5 4 | 5 | echo oops -- return in source.sub2 failed 6 | -------------------------------------------------------------------------------- /tests/nquote1.sub: -------------------------------------------------------------------------------- 1 | set -o history 2 | set -H 3 | 4 | echo $'hello\' world' 5 | echo $'hello world!' 6 | echo $'hello\' world!' 7 | -------------------------------------------------------------------------------- /tests/run-casemod: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./casemod.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} casemod.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-comsub: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./comsub.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} comsub.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-coproc: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./coproc.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} coproc.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-cprint: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./cprint.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} cprint.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-dollars: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./dollar-at-star > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} dollar.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-getopts: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./getopts.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} getopts.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-herestr: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./herestr.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} herestr.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-input-test: -------------------------------------------------------------------------------- 1 | ${THIS_SH} < ./input-line.sh > ${BASH_TSTOUT} 2 | diff ${BASH_TSTOUT} input.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-mapfile: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./mapfile.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} mapfile.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-parser: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./parser.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} parser.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-posixpat: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./posixpat.tests > ${BASH_TSTOUT} 2 | diff ${BASH_TSTOUT} posixpat.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-rhs-exp: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./rhs-exp.tests 2>&1 > ${BASH_TSTOUT} 2 | diff ${BASH_TSTOUT} rhs-exp.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-vredir: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./vredir.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} vredir.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/trap1.sub: -------------------------------------------------------------------------------- 1 | # signals ignored at shell startup cannot be trapped or reset 2 | trap 'echo USR2' USR2 3 | 4 | trap -p USR2 5 | -------------------------------------------------------------------------------- /tests/extglob2.sub: -------------------------------------------------------------------------------- 1 | LANG=en_US.UTF-8 2 | 3 | shopt -s extglob 4 | a="aaaäöü" 5 | 6 | echo "${a}" "${a//?aa}" "${a//\aaa}" 7 | exit 0 8 | -------------------------------------------------------------------------------- /tests/run-appendop: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./appendop.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} appendop.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-arith-for: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./arith-for.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} arith-for.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-ifs-posix: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./ifs-posix.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} ifs-posix.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-lastpipe: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./lastpipe.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} lastpipe.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-posixexp: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./posixexp.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} posixexp.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-posixexp2: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./posixexp2.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} posixexp2.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-posixpipe: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./posixpipe.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} posixpipe.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /lib/glob/doc/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | cp glob.texi glob.info 3 | 4 | clean distclean mostlyclean maintainer-clean: 5 | rm -f glob.?? glob.info 6 | -------------------------------------------------------------------------------- /tests/exec2.sub: -------------------------------------------------------------------------------- 1 | # make sure an exit command in an exit trap sets the shell's exit status 2 | trap - 0 3 | trap 'exit 5' 0 4 | 5 | exit 0 6 | -------------------------------------------------------------------------------- /tests/run-attr: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./attr.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT} 2 | diff ${BASH_TSTOUT} attr.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-comsub-eof: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./comsub-eof.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} comsub-eof.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-exportfunc: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./exportfunc.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} exportfunc.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/dollar-at3.sub: -------------------------------------------------------------------------------- 1 | set -u 2 | 3 | echo ${#@} 4 | echo ${@:-bar} 5 | 6 | echo $@ 7 | echo after 1 8 | echo ${@} 9 | echo after 2 10 | -------------------------------------------------------------------------------- /tests/dollar-star4.sub: -------------------------------------------------------------------------------- 1 | set -u 2 | 3 | echo ${#*} 4 | echo ${*:-bar} 5 | 6 | echo $* 7 | echo after 1 8 | echo ${*} 9 | echo after 2 10 | -------------------------------------------------------------------------------- /tests/run-comsub-posix: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./comsub-posix.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} comsub-posix.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-exp-tests: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./exp.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT} 2 | diff ${BASH_TSTOUT} exp.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-varenv: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./varenv.sh 2>&1 | grep -v '^expect' > ${BASH_TSTOUT} 2 | diff ${BASH_TSTOUT} varenv.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/coproc.right: -------------------------------------------------------------------------------- 1 | 63 60 2 | a b c 3 | 63 60 4 | flop 5 | coproc.tests: REFLECT: status 143 6 | 63 60 7 | FOO 8 | 63 60 9 | root 10 | -1 -1 11 | -------------------------------------------------------------------------------- /tests/input.right: -------------------------------------------------------------------------------- 1 | before calling input-line.sub 2 | line read by ./input-line.sub was `this line for input-line.sub' 3 | finished with input-line.sub 4 | -------------------------------------------------------------------------------- /tests/misc/sigint-3.sh: -------------------------------------------------------------------------------- 1 | sleep 5 & 2 | sleep 5 & 3 | sleep 5 & 4 | 5 | echo wait 1 6 | wait 7 | 8 | echo wait 2 9 | wait 10 | 11 | exit 12 | -------------------------------------------------------------------------------- /tests/nameref9.sub: -------------------------------------------------------------------------------- 1 | arr=( idx1 idx2 ) 2 | i='arr[1]' 3 | echo ${!i} 4 | echo ${!i/x/X} 5 | 6 | typeset -n f='arr[1]' 7 | echo ${f} 8 | echo ${f/x/X} 9 | -------------------------------------------------------------------------------- /tests/run-invert: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./invert.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT} 2 | diff ${BASH_TSTOUT} invert.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-nquote: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./nquote.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT} 2 | diff ${BASH_TSTOUT} nquote.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-nquote5: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./nquote5.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT} 2 | diff ${BASH_TSTOUT} nquote5.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/run-posix2: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./posix2.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT} 2 | diff ${BASH_TSTOUT} posix2.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/ifs.right: -------------------------------------------------------------------------------- 1 | a:b:c 2 | a:b:c 3 | a:b:c 4 | a b c d e 5 | a:b:c:d:e 6 | a b c d e 7 | a:b:c:d:e 8 | a:b:c:d:e 9 | a b c d e 10 | a b c d e 11 | -------------------------------------------------------------------------------- /tests/run-more-exp: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./more-exp.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT} 2 | diff ${BASH_TSTOUT} more-exp.right && rm -f ${BASH_TSTOUT} 3 | -------------------------------------------------------------------------------- /tests/type1.sub: -------------------------------------------------------------------------------- 1 | foo() 2 | { 3 | echo $(/dev/null 3 | 4 | wait "$!" 5 | echo $? 6 | -------------------------------------------------------------------------------- /tests/run-test: -------------------------------------------------------------------------------- 1 | unset GROUPS UID 2>/dev/null 2 | 3 | ${THIS_SH} ./test.tests >${BASH_TSTOUT} 2>&1 4 | diff ${BASH_TSTOUT} test.right && rm -f ${BASH_TSTOUT} 5 | -------------------------------------------------------------------------------- /tests/trap3.sub: -------------------------------------------------------------------------------- 1 | PS4='+[$LINENO] ' 2 | trap 'echo trap: $LINENO' ERR 3 | 4 | set -x 5 | 6 | echo 1 7 | echo 2 8 | echo 3 | cat | false 9 | echo 4 10 | -------------------------------------------------------------------------------- /po/quot.sed: -------------------------------------------------------------------------------- 1 | s/"\([^"]*\)"/“\1”/g 2 | s/`\([^`']*\)'/‘\1’/g 3 | s/ '\([^`']*\)' / ‘\1’ /g 4 | s/ '\([^`']*\)'$/ ‘\1’/g 5 | s/^'\([^`']*\)' /‘\1’ /g 6 | s/“”/""/g 7 | -------------------------------------------------------------------------------- /tests/dbg-support2.right: -------------------------------------------------------------------------------- 1 | lineno: 17 (6) main 2 | lineno: 18 (6) main 3 | x is 1 4 | lineno: 19 (6) main 5 | lineno: 20 (6) main 6 | lineno: 21 (6) main 7 | x is 1 8 | -------------------------------------------------------------------------------- /tests/lastpipe1.sub: -------------------------------------------------------------------------------- 1 | # with lastpipe set, exit at the end of a pipeline exits 2 | # the calling shell 3 | shopt -s lastpipe 4 | exit 142 | exit 14 5 | echo after: $? 6 | -------------------------------------------------------------------------------- /tests/run-extglob3: -------------------------------------------------------------------------------- 1 | PATH=$PATH:`pwd` 2 | export PATH 3 | ${THIS_SH} ./extglob3.tests > ${BASH_TSTOUT} 4 | diff ${BASH_TSTOUT} extglob3.right && rm -f ${BASH_TSTOUT} 5 | -------------------------------------------------------------------------------- /tests/array3.sub: -------------------------------------------------------------------------------- 1 | a=(0 1 2 3 4 5 6 7 8 9) 2 | 3 | echo ${a[@]: -1} 4 | 5 | echo ${a[@]:9} 6 | echo ${a[@]:10} 7 | echo ${a[@]:11} 8 | 9 | echo ${a[@]:7:3} 10 | -------------------------------------------------------------------------------- /tests/dollar-at4.sub: -------------------------------------------------------------------------------- 1 | set 'a b' 'c d' 2 | 3 | recho "$@" 4 | recho $@ 5 | 6 | quoted="$@" 7 | unquoted=$@ 8 | 9 | recho "$quoted" 10 | recho "$unquoted" 11 | -------------------------------------------------------------------------------- /tests/misc/sigint-1.sh: -------------------------------------------------------------------------------- 1 | echo before trap 2 | trap 'echo caught sigint' 2 3 | echo after trap 4 | 5 | for i in 1 2 3 6 | do 7 | echo $i 8 | sleep 5 9 | done 10 | -------------------------------------------------------------------------------- /tests/run-globstar: -------------------------------------------------------------------------------- 1 | PATH=$PATH:`pwd` 2 | export PATH 3 | ${THIS_SH} ./globstar.tests > ${BASH_TSTOUT} 2>&1 4 | diff ${BASH_TSTOUT} globstar.right && rm -f ${BASH_TSTOUT} 5 | -------------------------------------------------------------------------------- /tests/vredir3.sub: -------------------------------------------------------------------------------- 1 | # Right now, the {varname} mechanism does not honor set -u for compatibility 2 | unset v 3 | set -u 4 | exec {v}>&- 5 | 6 | echo after 7 | 8 | exit 0 9 | -------------------------------------------------------------------------------- /tests/nameref2.sub: -------------------------------------------------------------------------------- 1 | # test readonly nameref variables 2 | # ksh93 allows this but not typeset -rn ref=foo? 3 | typeset -n ref=foo 4 | readonly ref 5 | foo=4 6 | 7 | echo $ref 8 | -------------------------------------------------------------------------------- /po/LINGUAS: -------------------------------------------------------------------------------- 1 | # Set of available languages. 2 | en@quot en@boldquot af bg ca cs da de el eo es et fi fr ga gl hr hu id it ja lt nb nl pl pt_BR ro ru sk sl sr sv tr uk vi zh_CN zh_TW 3 | -------------------------------------------------------------------------------- /tests/misc/sigint-4.sh: -------------------------------------------------------------------------------- 1 | trap 'echo sigint' 2 2 | 3 | sleep 5 & 4 | sleep 5 & 5 | sleep 5 & 6 | 7 | echo wait 1 8 | wait 9 | 10 | echo wait 2 11 | wait 12 | 13 | exit 14 | -------------------------------------------------------------------------------- /tests/strip.right: -------------------------------------------------------------------------------- 1 | '' 2 | ' ab ' 3 | ' ' 4 | '' 5 | '' 6 | '' 7 | 'ababababababab' 8 | 'ababababababab ' 9 | 'ababababababab ' 10 | 'abababa 11 | bababab ' 12 | '' 13 | -------------------------------------------------------------------------------- /tests/errors5.sub: -------------------------------------------------------------------------------- 1 | array[1]=one 2 | array[2]=two 3 | 4 | set -u 5 | 6 | ( echo ${#array} ) 7 | ( echo ${array} ) 8 | 9 | set -- 1 2 3 10 | ( echo ${#7} ) 11 | ( echo ${7} ) 12 | -------------------------------------------------------------------------------- /tests/mapfile2.sub: -------------------------------------------------------------------------------- 1 | # test mapfile -d DELIM functionality added after bash-4.3 2 | 3 | printf "abc\0def\0ghi\0jkl\0" | { 4 | mapfile -C echo -c 1 -d '' A 5 | echo "${A[@]}" 6 | } 7 | -------------------------------------------------------------------------------- /tests/parser.tests: -------------------------------------------------------------------------------- 1 | # catch-all for parsing problems that don't fit anywhere else 2 | 3 | # this has to be in a separate file to get desired EOF behavior 4 | ${THIS_SH} ./parser1.sub 5 | -------------------------------------------------------------------------------- /tests/run-errors: -------------------------------------------------------------------------------- 1 | unset OLDPWD # make sure shell doesn't inherit OLDPWD 2 | ${THIS_SH} ./errors.tests > ${BASH_TSTOUT} 2>&1 3 | diff ${BASH_TSTOUT} errors.right && rm -f ${BASH_TSTOUT} 4 | -------------------------------------------------------------------------------- /tests/run-extglob: -------------------------------------------------------------------------------- 1 | PATH=$PATH:`pwd` 2 | export PATH 3 | ${THIS_SH} ./extglob.tests | grep -v '^expect' > ${BASH_TSTOUT} 4 | diff ${BASH_TSTOUT} extglob.right && rm -f ${BASH_TSTOUT} 5 | -------------------------------------------------------------------------------- /tests/run-extglob2: -------------------------------------------------------------------------------- 1 | PATH=$PATH:`pwd` 2 | export PATH 3 | ${THIS_SH} ./extglob2.tests | grep -v '^expect' > ${BASH_TSTOUT} 4 | diff ${BASH_TSTOUT} extglob2.right && rm -f ${BASH_TSTOUT} 5 | -------------------------------------------------------------------------------- /tests/run-glob-test: -------------------------------------------------------------------------------- 1 | PATH=$PATH:`pwd` 2 | export PATH 3 | ${THIS_SH} ./glob.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT} 4 | diff ${BASH_TSTOUT} glob.right && rm -f ${BASH_TSTOUT} 5 | -------------------------------------------------------------------------------- /tests/redir1.sub: -------------------------------------------------------------------------------- 1 | # 2 | # Test the effect of input buffering on the shell's input 3 | # 4 | echo this is redir1.sub 5 | 6 | exec 0< redir2.sub 7 | 8 | echo BUG: after exec in redir1.sub 9 | -------------------------------------------------------------------------------- /tests/vredir1.sub: -------------------------------------------------------------------------------- 1 | bar() 2 | { 3 | exec {v}<&2 ; exit 2 ;; 7 | esac 8 | -------------------------------------------------------------------------------- /tests/version.mini: -------------------------------------------------------------------------------- 1 | echo Testing ${THIS_SH} 2 | 3 | echo version: $BASH_VERSION 4 | #echo versinfo: ${BASH_VERSINFO[@]} 5 | 6 | echo HOSTTYPE = $HOSTTYPE 7 | echo OSTYPE = $OSTYPE 8 | echo MACHTYPE = $MACHTYPE 9 | -------------------------------------------------------------------------------- /tests/builtins2.sub: -------------------------------------------------------------------------------- 1 | # test behavior of shopt xpg_echo 2 | 3 | USG_ECHO=off 4 | shopt -q xpg_echo && USG_ECHO=on 5 | 6 | shopt -u xpg_echo 7 | echo 'a\n\n\nb' 8 | 9 | shopt -s xpg_echo 10 | echo 'a\n\n\nb' 11 | -------------------------------------------------------------------------------- /tests/misc/test-minus-e.1: -------------------------------------------------------------------------------- 1 | touch .file 2 | while set -e ; test -r .file ; do 3 | echo -n "stop loop? " 4 | read reply 5 | case "$reply" in 6 | y*) rm .file non-dash-file ;; 7 | esac 8 | set +e 9 | done 10 | -------------------------------------------------------------------------------- /Y2K: -------------------------------------------------------------------------------- 1 | Since Bash does not manipulate date strings, it is Y2K-safe. 2 | 3 | The only thing that Bash does with date strings is manipulate the string 4 | returned by ctime(3) or strftime(3) in the prompt customization code. 5 | -------------------------------------------------------------------------------- /tests/dollar-star5.sub: -------------------------------------------------------------------------------- 1 | set -- a b 2 | IFS= 3 | 4 | echo $* 5 | echo "$*" 6 | 7 | a=abcd 8 | echo "${a#$*}" 9 | 10 | case ab in 11 | $*) echo ok 1;; 12 | esac 13 | 14 | case $* in 15 | ab) echo ok 2 ;; 16 | esac 17 | -------------------------------------------------------------------------------- /tests/exp3.sub: -------------------------------------------------------------------------------- 1 | IFS=: 2 | 3 | case A in ([[:graph:]]) echo graph;; *) echo non-graph;; esac 4 | [[ A == [[:graph:]] ]] && echo yes || echo no 5 | 6 | IFS="~"; read a b <<< a~q; echo $a 7 | IFS=':'; read a b <<< a:q; echo $a 8 | -------------------------------------------------------------------------------- /tests/getopts8.sub: -------------------------------------------------------------------------------- 1 | f() 2 | { 3 | typeset OPTIND=1 4 | typeset opt 5 | 6 | while getopts ":abcxyz" opt 7 | do 8 | echo opt: "$opt" 9 | if [[ $opt = y ]]; then f -abc ; fi 10 | done 11 | } 12 | 13 | f -xyz 14 | -------------------------------------------------------------------------------- /tests/jobs5.sub: -------------------------------------------------------------------------------- 1 | # framework to test new `wait -n' option that waits for any job to finish 2 | 3 | set -m 4 | 5 | sleep 20 & 6 | { sleep 5; exit 12; } & 7 | sleep 20 & 8 | 9 | wait -n 10 | echo $? 11 | 12 | jobs 13 | -------------------------------------------------------------------------------- /tests/comsub2.sub: -------------------------------------------------------------------------------- 1 | qpath='\/tmp\/foo\/bar' 2 | 3 | echo "$qpath" 4 | 5 | # it's crazy that all three of these produce the same result 6 | echo ${qpath//\\/} 7 | echo ${qpath//"`echo \\`"/} 8 | echo ${qpath//`echo "\\\\\\\\"`/} 9 | -------------------------------------------------------------------------------- /tests/history2.sub: -------------------------------------------------------------------------------- 1 | set -o history 2 | HISTSIZE=256 3 | HISTFILE=/dev/null 4 | 5 | # these two lines should be the same 6 | echo ${BASH_VERSION%\.*} 7 | echo $(fc -nl -1) 8 | 9 | echo ${BASH_VERSION%\.*} 10 | fc -nl -1 11 | -------------------------------------------------------------------------------- /tests/new-exp7.sub: -------------------------------------------------------------------------------- 1 | foo() 2 | { 3 | echo < <(cat x1) 4 | } 5 | 6 | type foo 7 | 8 | declare -f foo 9 | 10 | echo $(declare -f foo | sed 's:foo:bar:') 11 | eval "$(declare -f foo | sed 's:foo:bar:')" 12 | 13 | type bar 14 | -------------------------------------------------------------------------------- /po/boldquot.sed: -------------------------------------------------------------------------------- 1 | s/"\([^"]*\)"/“\1”/g 2 | s/`\([^`']*\)'/‘\1’/g 3 | s/ '\([^`']*\)' / ‘\1’ /g 4 | s/ '\([^`']*\)'$/ ‘\1’/g 5 | s/^'\([^`']*\)' /‘\1’ /g 6 | s/“”/""/g 7 | s/“/“/g 8 | s/”/”/g 9 | s/‘/‘/g 10 | s/’/’/g 11 | -------------------------------------------------------------------------------- /tests/builtins1.sub: -------------------------------------------------------------------------------- 1 | unset CDPATH 2 | 3 | MYDIR=$(pwd -P) 4 | FULLDIR=/tmp/bash-dir-a 5 | DIR=${FULLDIR##*/} 6 | 7 | mkdir $FULLDIR 8 | CDPATH=.:/tmp 9 | cd $DIR 10 | pwd 11 | echo $PWD 12 | 13 | cd "$MYDIR" 14 | rmdir $FULLDIR 15 | -------------------------------------------------------------------------------- /tests/builtins3.sub: -------------------------------------------------------------------------------- 1 | # declare -g added in bash-4.2 2 | f=4 3 | 4 | foo() 5 | { 6 | declare -g f=8 7 | declare -g bar=4 8 | 9 | echo inside 10 | } 11 | 12 | echo before: f = $f 13 | foo 14 | echo after: f = $f bar = $bar 15 | -------------------------------------------------------------------------------- /tests/dollar-at2.sub: -------------------------------------------------------------------------------- 1 | t1() 2 | { 3 | xxx="echo $@" 4 | 5 | recho "$xxx ; echo $@" 6 | } 7 | 8 | t2() 9 | { 10 | xxx="echo $@" 11 | 12 | recho "${xxx} ; echo $@" 13 | } 14 | 15 | t1 1 16 | t1 1 2 17 | 18 | t2 1 19 | t2 1 2 20 | -------------------------------------------------------------------------------- /tests/unicode3.sub: -------------------------------------------------------------------------------- 1 | export LANG=en_US.UTF-8 # make sure 2 | payload=$'\065\247\100\063\231\053\306\123\070\237\242\352\263' 3 | "$payload" 4 | 5 | cd "$payload" 6 | printf %q "$payload" 7 | echo 8 | 9 | set -x ; : "$payload" 10 | -------------------------------------------------------------------------------- /tests/exp7.sub: -------------------------------------------------------------------------------- 1 | IFS=$'\001' 2 | c=$'\001' 3 | c2=$'\003' 4 | 5 | IFS=$c # this is the problem line, IFS should end up being \001 6 | recho "$IFS" 7 | set -- $c2$c$c2$c$c2 8 | recho $# "$1" "$2" "$3" 9 | 10 | x=$c 11 | recho "$x" 12 | -------------------------------------------------------------------------------- /tests/intl1.sub: -------------------------------------------------------------------------------- 1 | LC_ALL=en_US.UTF-8 2 | LANG=en_US.UTF-8 3 | 4 | var='абвгдежзиклмноп ' 5 | echo -"$var"- ${#var} 6 | 7 | read foo <<< "$var" 8 | echo -"$foo"- ${#foo} 9 | 10 | read -n 5 foo <<< "$var" 11 | echo -"$foo"- ${#foo} 12 | -------------------------------------------------------------------------------- /tests/run-assoc: -------------------------------------------------------------------------------- 1 | echo "warning: all of these tests will fail if arrays have not" >&2 2 | echo "warning: been compiled into the shell" >&2 3 | ${THIS_SH} ./assoc.tests > ${BASH_TSTOUT} 2>&1 4 | diff ${BASH_TSTOUT} assoc.right && rm -f ${BASH_TSTOUT} 5 | -------------------------------------------------------------------------------- /tests/run-dirstack: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./dstack.tests > ${BASH_TSTOUT} 2>&1 2 | diff ${BASH_TSTOUT} dstack.right && rm -f ${BASH_TSTOUT} 3 | 4 | ${THIS_SH} ./dstack2.tests > ${BASH_TSTOUT} 2>&1 5 | diff ${BASH_TSTOUT} dstack2.right && rm -f ${BASH_TSTOUT} 6 | -------------------------------------------------------------------------------- /tests/arith7.sub: -------------------------------------------------------------------------------- 1 | PARAM=abcdefg 2 | 3 | echo ${PARAM:1 ? 4 : 2} 4 | echo ${PARAM:1 ? 4 : 2:1} 5 | 6 | echo ${PARAM: 4<5 ? 4 : 2} 7 | echo ${PARAM: 5>4 ? 4 : 2:1} 8 | 9 | echo ${PARAM:${OFFSET:-0}} 10 | OFFSET=4 11 | echo ${PARAM:${OFFSET:-0}} 12 | -------------------------------------------------------------------------------- /tests/comsub-eof.tests: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./comsub-eof0.sub 2 | 3 | ${THIS_SH} ./comsub-eof1.sub 4 | 5 | ${THIS_SH} ./comsub-eof2.sub 6 | 7 | ${THIS_SH} ./comsub-eof3.sub 8 | 9 | ${THIS_SH} ./comsub-eof4.sub 10 | 11 | ${THIS_SH} ./comsub-eof5.sub 12 | -------------------------------------------------------------------------------- /tests/history1.sub: -------------------------------------------------------------------------------- 1 | trap 'rm -f $HISTFILE' 0 1 2 3 6 15 2 | 3 | HISTFILE=$TMPDIR/foohist-$$ 4 | unset HISTIGNORE HISTCONTROL 5 | set -o history 6 | 7 | history -c 8 | cat <&2 2 | echo "warning: been compiled into the shell" >&2 3 | ${THIS_SH} ./array-at-star > ${BASH_TSTOUT} 2>&1 4 | diff ${BASH_TSTOUT} array2.right && rm -f ${BASH_TSTOUT} 5 | -------------------------------------------------------------------------------- /tests/run-history: -------------------------------------------------------------------------------- 1 | echo "warning: all of these tests will fail if history has not been compiled" >&2 2 | echo "warning: into the shell" >&2 3 | ${THIS_SH} ./history.tests > ${BASH_TSTOUT} 2>&1 4 | diff ${BASH_TSTOUT} history.right && rm -f ${BASH_TSTOUT} 5 | -------------------------------------------------------------------------------- /tests/run-nameref: -------------------------------------------------------------------------------- 1 | echo "warning: some of these tests will fail if arrays have not" >&2 2 | echo "warning: been compiled into the shell" >&2 3 | ${THIS_SH} ./nameref.tests > ${BASH_TSTOUT} 2>&1 4 | diff ${BASH_TSTOUT} nameref.right && rm -f ${BASH_TSTOUT} 5 | -------------------------------------------------------------------------------- /tests/vredir6.sub: -------------------------------------------------------------------------------- 1 | unset v 2 | exec {v}= 10 )); then echo ok 1; else echo bad 1; fi 5 | 6 | exec {v}<&- 7 | 8 | ulimit -n 6 9 | 10 | exec &2 2 | echo "warning: into the shell" >&2 3 | ${THIS_SH} ./histexp.tests > ${BASH_TSTOUT} 2>&1 4 | diff ${BASH_TSTOUT} histexp.right && rm -f ${BASH_TSTOUT} 5 | -------------------------------------------------------------------------------- /tests/run-read: -------------------------------------------------------------------------------- 1 | echo "warning: please do not consider output differing only in the amount of" >&2 2 | echo "warning: white space to be an error." >&2 3 | ${THIS_SH} ./read.tests > ${BASH_TSTOUT} 2>&1 4 | diff ${BASH_TSTOUT} read.right && rm -f ${BASH_TSTOUT} 5 | -------------------------------------------------------------------------------- /doc/infopost.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # Some of these should really be done by options to makeinfo or by 4 | # using @setfilename, but this way we can have both bashref.info and 5 | # bash.info (for installing) 6 | # 7 | 8 | sed -e 's|bashref.info|bash.info|g' 9 | -------------------------------------------------------------------------------- /lib/tilde/README: -------------------------------------------------------------------------------- 1 | If you're building this separately from bash or the readline library, add 2 | $(srcdir)/shell.c to the CSOURCES variable and shell.o to the OBJECTS 3 | variable in Makefile.in. (Not that this is very useful without readline 4 | or bash.) 5 | 6 | -------------------------------------------------------------------------------- /tests/misc/test-minus-e.2: -------------------------------------------------------------------------------- 1 | touch .file 2 | set -e 3 | while set +e ; test -r .file ; do 4 | echo -n "stop loop? [yes to quit] " 5 | read reply 6 | if [ "$reply" = yes ] ; then 7 | rm .file non-dash-file 8 | fi 9 | set -e 10 | done 11 | rm -f .file 12 | -------------------------------------------------------------------------------- /tests/new-exp1.sub: -------------------------------------------------------------------------------- 1 | expect() 2 | { 3 | echo expect "$@" 4 | } 5 | 6 | expect this is a test of proc subst 7 | cat <(echo this is a test of proc subst) 8 | echo this is test 2 > /tmp/x 9 | expect this is test 2 10 | cat <(cat /tmp/x) 11 | rm -f /tmp/x 12 | -------------------------------------------------------------------------------- /tests/comsub-posix3.sub: -------------------------------------------------------------------------------- 1 | # parsing errors before bash-4.2 2 | 3 | a=$(/bin/cat << EOF | wc -l 4 | a 5 | b 6 | c 7 | EOF 8 | ) 9 | 10 | a=$(cat << EOF | wc -l 11 | a 12 | b 13 | c 14 | EOF 15 | ) 16 | 17 | a=$(/bin/cat << EOF 18 | a 19 | b 20 | c 21 | EOF 22 | ) 23 | -------------------------------------------------------------------------------- /tests/intl2.sub: -------------------------------------------------------------------------------- 1 | unset LC_ALL LC_NUMERIC 2 | export LANG=de_DE.UTF-8 3 | printf '%.4f\n' 1 4 | 5 | LANG=C printf '%.4f\n' 1 6 | LANG=C /usr/bin/printf '%.4f\n' 1 7 | 8 | env LANG=C printf '%.4f\n' 1 9 | (LANG=C; printf '%.4f\n' 1) 10 | 11 | printf '%.4f\n' 1 12 | -------------------------------------------------------------------------------- /tests/misc/redir-t2.sh: -------------------------------------------------------------------------------- 1 | read line1 2 | 3 | echo read line 1 \"$line1\" 4 | 5 | exec 4<&0 6 | 7 | exec 0/dev/null ; read -t 0; } 4 | echo $? 5 | 6 | read -t 0 < $0 7 | echo $? 8 | 9 | read -t 0 10 | echo $? 11 | -------------------------------------------------------------------------------- /tests/set-e3.sub: -------------------------------------------------------------------------------- 1 | foo() 2 | { 3 | echo A: 4 | . ./set-e3a.sub 5 | echo D: 6 | } 7 | 8 | # should run all the way through; foo being called in a context where set -e 9 | # is ignored means that that condition persists through sourcing the file 10 | foo && true 11 | -------------------------------------------------------------------------------- /examples/functions/inpath: -------------------------------------------------------------------------------- 1 | inpath() 2 | { 3 | local PROG 4 | path=$(echo $PATH | sed 's/^:/.:/ 5 | s/::/:.:/g 6 | s/:$/:./ 7 | s/:/ /g') 8 | 9 | for x in $path 10 | do 11 | [ -x $x/$1 ] && { PROG=$x/$1; break; } 12 | done 13 | [ -n "$PROG" ] 14 | } 15 | -------------------------------------------------------------------------------- /tests/glob1.sub: -------------------------------------------------------------------------------- 1 | # bash-2.01.1 failed this test 2 | FN=/tmp/bash-glob.$$ 3 | mkdir $FN 4 | cd $FN 5 | mkdir foo 6 | mkdir foobar 7 | touch foo/bar 8 | touch foobar/bar 9 | chmod 311 foo foobar 10 | echo f*/bar 11 | 12 | chmod 777 foo foobar 13 | cd / 14 | rm -rf $FN 15 | -------------------------------------------------------------------------------- /tests/run-nquote1: -------------------------------------------------------------------------------- 1 | echo "warning: several of these tests will fail if arrays have not" >&2 2 | echo "warning: been compiled into the shell." >&2 3 | ${THIS_SH} ./nquote1.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT} 4 | diff ${BASH_TSTOUT} nquote1.right && rm -f ${BASH_TSTOUT} 5 | -------------------------------------------------------------------------------- /tests/run-nquote2: -------------------------------------------------------------------------------- 1 | echo "warning: several of these tests will fail if arrays have not" >&2 2 | echo "warning: been compiled into the shell." >&2 3 | ${THIS_SH} ./nquote2.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT} 4 | diff ${BASH_TSTOUT} nquote2.right && rm -f ${BASH_TSTOUT} 5 | -------------------------------------------------------------------------------- /tests/run-nquote3: -------------------------------------------------------------------------------- 1 | echo "warning: several of these tests will fail if arrays have not" >&2 2 | echo "warning: been compiled into the shell." >&2 3 | ${THIS_SH} ./nquote3.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT} 4 | diff ${BASH_TSTOUT} nquote3.right && rm -f ${BASH_TSTOUT} 5 | -------------------------------------------------------------------------------- /tests/type3.sub: -------------------------------------------------------------------------------- 1 | cd ${TMPDIR:-/tmp} 2 | 3 | foo() { 4 | rm -f a b c 5 | for f in a b c; do 6 | cat <<-EOF >> ${f} 7 | file 8 | EOF 9 | done 10 | grep . a b c 11 | } 12 | 13 | type foo 14 | 15 | eval "$(type foo | sed 1d)" 16 | foo 17 | 18 | rm -f a b c 19 | -------------------------------------------------------------------------------- /tests/errors3.sub: -------------------------------------------------------------------------------- 1 | # redirection errors with special builtins should exit the shell when in 2 | # Posix mode, not otherwise; being on the LHS of || or && should not make 3 | # a difference 4 | 5 | exec 9&2 2 | echo warning: locales installed on your system >&2 3 | ${THIS_SH} ./nquote4.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT} 4 | diff ${BASH_TSTOUT} nquote4.right && rm -f ${BASH_TSTOUT} 5 | -------------------------------------------------------------------------------- /tests/test-glue-functions: -------------------------------------------------------------------------------- 1 | # shell functions to include in multiple test files 2 | 3 | # squeeze out blanks to avoid white space differences in od implementations 4 | _intl_normalize_spaces() 5 | { 6 | sed -e 's/[[:space:]]\{1,\}/ /g' -e 's/[[:space:]]*$//' 7 | } 8 | 9 | 10 | -------------------------------------------------------------------------------- /doc/version.texi: -------------------------------------------------------------------------------- 1 | @ignore 2 | Copyright (C) 1988-2016 Free Software Foundation, Inc. 3 | @end ignore 4 | 5 | @set LASTCHANGE Wed Sep 7 17:12:22 EDT 2016 6 | 7 | @set EDITION 4.4 8 | @set VERSION 4.4 9 | 10 | @set UPDATED 7 September 2016 11 | @set UPDATED-MONTH September 2016 12 | -------------------------------------------------------------------------------- /lib/readline/doc/version.texi: -------------------------------------------------------------------------------- 1 | @ignore 2 | Copyright (C) 1988-2016 Free Software Foundation, Inc. 3 | @end ignore 4 | 5 | @set EDITION 7.0 6 | @set VERSION 7.0 7 | @set UPDATED 16 July 2016 8 | @set UPDATED-MONTH July 2016 9 | 10 | @set LASTCHANGE Sat Jul 16 13:43:15 EDT 2016 11 | -------------------------------------------------------------------------------- /tests/assoc3.sub: -------------------------------------------------------------------------------- 1 | foo() 2 | { 3 | declare -A afoo=([six]="six" [foo bar]="foo quux") 4 | 5 | declare -A 6 | recho inside: "${afoo[@]}" 7 | } 8 | 9 | declare -A afoo=([main]=outside) 10 | echo outside: "${afoo[@]}" 11 | 12 | foo 13 | 14 | echo outside 2: "${afoo[@]}" 15 | 16 | -------------------------------------------------------------------------------- /examples/functions/shcat2: -------------------------------------------------------------------------------- 1 | shcat() 2 | { 3 | while read -r line 4 | do 5 | echo "$line" 6 | done 7 | } 8 | 9 | shcat2() 10 | { 11 | while [ $# -ge 1 ]; do 12 | case "$1" in 13 | -) shcat ;; 14 | *) shcat < "$1" ;; 15 | esac 16 | shift 17 | done 18 | exit 0 19 | } 20 | -------------------------------------------------------------------------------- /tests/jobs2.sub: -------------------------------------------------------------------------------- 1 | # make sure fg and bg don't work on jobs started without job control, 2 | # even if they are executed when job control is active 3 | set +o monitor 4 | 5 | sleep 30 & 6 | pid=$! 7 | 8 | set -m 9 | fg %1 10 | echo fg: $? 11 | 12 | exec 2>/dev/null 13 | kill -9 $pid 14 | -------------------------------------------------------------------------------- /tests/appendop1.sub: -------------------------------------------------------------------------------- 1 | typeset -A foo=([one]=bar [two]=baz [three]=quux) 2 | typeset -p foo 3 | 4 | foo+=zero 5 | typeset -p foo 6 | 7 | foo+=([four]=four) 8 | typeset -p foo 9 | 10 | typeset -ia iarr=(2 2 3) 11 | iarr+=1 12 | typeset -p iarr 13 | 14 | iarr+=(4 5 6) 15 | typeset -p iarr 16 | -------------------------------------------------------------------------------- /tests/lastpipe.right: -------------------------------------------------------------------------------- 1 | after 1: foo = a b c 2 | after 2: tot = 6 3 | after: 7 4 | last = c 5 | 1 -- 142 1 6 | 0 -- 0 1 0 7 | 1 -- 0 0 1 8 | 1 -- 0 0 1 9 | 1 -- 0 1 0 10 | lastpipe1.sub returns 14 11 | A1 12 | A2 13 | B1 14 | B2 15 | HI 16 | A1 17 | A2 18 | B1 19 | B2 20 | HI -- 42 -- 0 42 21 | -------------------------------------------------------------------------------- /tests/misc/perftest: -------------------------------------------------------------------------------- 1 | # originally from Mike Haertel 2 | foo() { case $1 in a*) ;; *) ;; esac ;} 3 | bar() { case $1 in [abc]*) ;; *);; esac ;} 4 | baz() { case $1 in xyzzy) ;; *) ;; esac ;} 5 | for x in /usr/lib/*/* 6 | do 7 | foo $x 8 | bar $x 9 | baz $x 10 | done 11 | -------------------------------------------------------------------------------- /tests/misc/read-nchars.tests: -------------------------------------------------------------------------------- 1 | # interactive 2 | 3 | # from tty 4 | read -n 3 -p 'enter three chars: ' xyz 5 | echo 6 | echo $xyz 7 | 8 | # using readline 9 | read -p 'enter 3 chars: ' -e -n 3 abc 10 | # readline outputs a newline for us, so we don't need the extra echo 11 | echo $abc 12 | -------------------------------------------------------------------------------- /tests/errors1.sub: -------------------------------------------------------------------------------- 1 | . -i /dev/tty 2 | 3 | f() 4 | { 5 | return -1 6 | } 7 | 8 | set -- a b c 9 | shift -4 10 | 11 | f 12 | 13 | for f in 1 2 3; do 14 | break -1 15 | done 16 | 17 | 18 | f() 19 | { 20 | return -25 21 | } 22 | 23 | f 24 | echo after f 25 | exit -25 26 | 27 | exit -56 28 | -------------------------------------------------------------------------------- /tests/exec5.sub: -------------------------------------------------------------------------------- 1 | # try exec'ing a command that cannot be found in $PATH 2 | shopt -s execfail 3 | 4 | exec bash-notthere 5 | # make sure we're still around 6 | echo $? 7 | 8 | # now we need to go away, but this should echo 'this is ohio-state' 9 | exec -a ohio-state ${THIS_SH} -c 'echo this is $0' 10 | -------------------------------------------------------------------------------- /tests/getopts10.sub: -------------------------------------------------------------------------------- 1 | set -- -a bb 2 | readonly OPTARG 3 | getopts :x x 4 | 5 | echo OPTARG = $OPTARG x = $x 6 | 7 | getopts x x 8 | echo ${OPTARG-unset} x = $x 9 | 10 | typeset -r RO=foo 11 | typeset -n OPTARG=RO 12 | 13 | getopts :x x 14 | typeset -p RO 15 | 16 | getopts x x 17 | typeset -p RO 18 | -------------------------------------------------------------------------------- /tests/vredir4.sub: -------------------------------------------------------------------------------- 1 | swizzle() 2 | { 3 | fd0=0 4 | fd1=1 5 | 6 | exec {stdin}<&$fd0 7 | exec {stdout}>&$fd1 8 | } 9 | 10 | swizzle 11 | echo $stdin $stdout 12 | 13 | read line <&$stdin <&$stdout 19 | 20 | type swizzle 21 | 22 | exit 0 23 | -------------------------------------------------------------------------------- /tests/dollar-star2.sub: -------------------------------------------------------------------------------- 1 | set A B 2 | 3 | IFS= 4 | 5 | x=$* 6 | y="$*" 7 | 8 | recho "$x" 9 | recho "$y" 10 | 11 | IFS=$' \t\n' 12 | 13 | set 'A B' 'C D' 14 | 15 | IFS= 16 | 17 | x=$* 18 | y="$*" 19 | 20 | recho "$x" 21 | recho "$y" 22 | 23 | recho $x 24 | recho $* 25 | recho $y 26 | recho "$*" 27 | -------------------------------------------------------------------------------- /tests/mapfile1.sub: -------------------------------------------------------------------------------- 1 | : ${TMPDIR:=/tmp} 2 | FILE=$TMPDIR/file 3 | 4 | trap 'rm -f $FILE' 0 1 2 3 6 15 5 | printf "%d\n" {1..20} > $FILE 6 | 7 | mapfile -n 5 array < $FILE 8 | echo ${array[@]} 9 | 10 | mapfile -n 5 -c 1 -C "echo foo" array < $FILE 11 | mapfile -n 5 -c 1 -C "echo foo" array < /dev/null 12 | -------------------------------------------------------------------------------- /tests/misc/dev-tcp.tests: -------------------------------------------------------------------------------- 1 | exec 9<>/dev/tcp/129.22.8.162/25 2 | 3 | read banner <&9 4 | echo "$banner" 5 | 6 | echo quit >&9 7 | 8 | read msg <&9 9 | echo "$msg" 10 | 11 | exec 9<&- 12 | 13 | # nifty date command that queries the date/time server 14 | cat < /dev/tcp/129.22.8.102/13 15 | 16 | exit 0 17 | -------------------------------------------------------------------------------- /tests/varenv5.sub: -------------------------------------------------------------------------------- 1 | function foobar { 2 | declare -rgA FOOBAR=([foo]=bar) 3 | declare -p FOOBAR 4 | } 5 | foobar 6 | declare -p FOOBAR 7 | 8 | unset -f foobar 9 | 10 | foobar() { 11 | declare -rga FOOBAR2=([foo]=bar) 12 | declare -p FOOBAR2 13 | } 14 | 15 | foobar 16 | declare -p FOOBAR2 17 | -------------------------------------------------------------------------------- /lib/readline/README: -------------------------------------------------------------------------------- 1 | This is the distribution of the Gnu Readline library. See the file 2 | STANDALONE for a description of the #defines that can be passed via 3 | the makefile to build readline on different systems. 4 | 5 | The file rlconf.h contains defines that enable and disable certain 6 | readline features. 7 | -------------------------------------------------------------------------------- /tests/array13.sub: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | func1(){ 4 | declare -g variable='function' 5 | declare -g -a array=(function) 6 | echo ${variable} ${array[@]} 7 | } 8 | 9 | declare -g variable='main' 10 | declare -g -a array=(main) 11 | echo ${variable} ${array[@]} 12 | func1 13 | echo ${variable} ${array[@]} 14 | -------------------------------------------------------------------------------- /tests/extglob3.sub: -------------------------------------------------------------------------------- 1 | shopt -s extglob 2 | DIR=/tmp/extglob-$$ 3 | mkdir $DIR 4 | cd $DIR 5 | 6 | touch a.log 7 | 8 | echo *(.) 9 | echo *(.)* 10 | echo ?(foo)* 11 | echo ?(foo) 12 | echo *(foo)* 13 | echo @(|foo)* 14 | 15 | echo *(foo).* 16 | 17 | echo !(foo)* 18 | 19 | cd $OLDPWD 20 | rm -rf $DIR 21 | 22 | -------------------------------------------------------------------------------- /tests/exportfunc1.sub: -------------------------------------------------------------------------------- 1 | cat <&2 2 | echo "warning: they may show up as diff output." >&2 3 | echo "warning: if so, please do not consider this a test failure" >&2 4 | ${THIS_SH} ./func.tests > ${BASH_TSTOUT} 2>&1 5 | diff ${BASH_TSTOUT} func.right && rm -f ${BASH_TSTOUT} 6 | -------------------------------------------------------------------------------- /tests/vredir5.sub: -------------------------------------------------------------------------------- 1 | swizzle() 2 | { 3 | exec {fd0}<&0 4 | exec {fd1}>&1 5 | 6 | exec {stdin}<&$fd0- 7 | exec {stdout}>&$fd1- 8 | } 9 | 10 | swizzle 11 | 12 | echo $stdin $stdout 13 | 14 | read line <&$stdin <&$stdout 20 | 21 | type swizzle 22 | 23 | exit 0 24 | -------------------------------------------------------------------------------- /tests/dollar-star6.sub: -------------------------------------------------------------------------------- 1 | recho "A${*:-w}R" 2 | recho "A${*-w}R" 3 | recho "A${*}R" 4 | 5 | set -- "" 6 | 7 | recho "A${*:-w}R" 8 | recho "A${*-w}R" 9 | recho "A${*}R" 10 | 11 | set -- $'\177' 12 | 13 | recho "A${*:+w}R" 14 | recho "A${*+w}R" 15 | recho "A${*}R" 16 | 17 | recho A${*:+w}R 18 | recho A${*+w}R 19 | recho A${*}R 20 | -------------------------------------------------------------------------------- /tests/jobs1.sub: -------------------------------------------------------------------------------- 1 | # make sure that jobs -p, %+, and $! all agree 2 | set -m 3 | sleep 60 & 4 | 5 | FN=/tmp/jobs-pid.$$ 6 | 7 | pid1=$! 8 | jobs -p %+ > $FN 9 | pid2=$(< $FN) 10 | rm $FN 11 | 12 | if [ $pid1 -ne $pid2 ]; then 13 | echo 'oops - $! and jobs -p %+ disagree!' 14 | fi 15 | 16 | exec 2>/dev/null 17 | kill -9 $pid1 18 | -------------------------------------------------------------------------------- /tests/run-builtins: -------------------------------------------------------------------------------- 1 | echo "warning: some of these tests may fail if process substitution has not" >&2 2 | echo "warning: been compiled into the shell or if the OS does not provide" >&2 3 | echo "warning: /dev/fd." >&2 4 | 5 | ${THIS_SH} ./builtins.tests > ${BASH_TSTOUT} 2>&1 6 | diff ${BASH_TSTOUT} builtins.right && rm -f ${BASH_TSTOUT} 7 | -------------------------------------------------------------------------------- /tests/varenv8.sub: -------------------------------------------------------------------------------- 1 | FOO=bar cat < <(echo $FOO:1; echo $FOO:2) 2 | echo after: --${FOO}-- 3 | 4 | unset FOO 5 | FOO=global 6 | 7 | FOO=bar cat < <(echo $FOO:1; echo $FOO:2) 8 | echo after: --${FOO}-- 9 | 10 | unset FOO 11 | FOO=bar read x < <(echo -n $FOO:1; echo $FOO:2) 12 | echo after: --${FOO}-- 13 | echo x = $x 14 | 15 | -------------------------------------------------------------------------------- /examples/loadables/perl/README: -------------------------------------------------------------------------------- 1 | This illustrates how to build a perl interpreter into bash. It's not 2 | especially useful; more a proof of concept (it provides none of the 3 | bash internals to the perl interpreter, for example). 4 | 5 | This *may* require adding "-rpath /path/to/perl/CORE" and -lperl options 6 | when compiling bash itself. 7 | -------------------------------------------------------------------------------- /tests/appendop2.sub: -------------------------------------------------------------------------------- 1 | POSIXLY_CORRECT=1 2 | x=2 3 | x+=5 eval printf '"$x "' 4 | echo "$x" 5 | 6 | unset x 7 | typeset -i x=2 8 | x+=5 eval printf '"$x "' 9 | echo "$x" 10 | 11 | a=1 12 | a+=4 13 | echo $a 14 | 15 | # idiotically, ksh93 makes these two cases differ (?) 16 | a+=5 printenv a 17 | a+=5 eval printf '"$a "' 18 | echo $a 19 | -------------------------------------------------------------------------------- /tests/exp2.sub: -------------------------------------------------------------------------------- 1 | K=dvb0.net A=${K#dvb} eval echo \$A 2 | unset K A 3 | x=${K:=dvb0.net0} A=${K#dvb} eval echo \$A 4 | 5 | unset K A 6 | K=dvb0.net A=${K#dvb} echo "$A" 7 | unset K A 8 | K=dvb0.net A=${K#dvb} ; echo "$A" 9 | unset K A 10 | K=dvb0.net A=${K#dvb} eval echo '$A' 11 | unset K A 12 | K=dvb0.net A=${K#dvb} eval echo \$A 13 | -------------------------------------------------------------------------------- /tests/extglob1a.sub: -------------------------------------------------------------------------------- 1 | shopt -s extglob 2 | 3 | TESTDIR=${TMPDIR:-/tmp}/eglob-test-$$ 4 | mkdir $TESTDIR 5 | builtin cd $TESTDIR || { echo $0: cannot cd to $TESTDIR >&2 ; exit 1; } 6 | rm -rf * 7 | 8 | touch a ab ba 9 | 10 | echo a*!(x) 11 | echo a!(x) 12 | echo a*?(x) 13 | echo a?(x) 14 | 15 | builtin cd / 16 | rm -rf $TESTDIR 17 | -------------------------------------------------------------------------------- /tests/vredir7.sub: -------------------------------------------------------------------------------- 1 | swizzle() 2 | { 3 | exec {fd[0]}<&0 4 | exec {fd[1]}>&1 5 | 6 | exec {stdin}<&${fd[0]}- 7 | exec {stdout}>&${fd[1]}- 8 | } 9 | 10 | swizzle 11 | 12 | echo $stdin $stdout 13 | 14 | read line <&$stdin <&$stdout 20 | 21 | type swizzle 22 | 23 | exit 0 24 | -------------------------------------------------------------------------------- /tests/attr2.sub: -------------------------------------------------------------------------------- 1 | p=1 2 | export p 3 | 4 | export p=4 5 | declare -p p 6 | 7 | r=(1) 8 | export r 9 | 10 | f() { export r=(4) ; } 11 | f 12 | declare -p r 13 | 14 | f() { export r='(5)' ; } 15 | f 16 | declare -p r 17 | 18 | f() { export -a r=(6) ; } 19 | f 20 | declare -p r 21 | 22 | f() { export -a r='(7)' ; } 23 | f 24 | declare -p r 25 | -------------------------------------------------------------------------------- /tests/assoc7.sub: -------------------------------------------------------------------------------- 1 | # problem with bash versions through bash-4.2 2 | foo() 3 | { 4 | declare -A hash 5 | declare hash[baz]=bar #bash crashes here 6 | 7 | echo ${hash[@]} 8 | } 9 | 10 | foo 11 | 12 | declare -a ary 13 | printf -v ary[0] "%b" "" 14 | echo "after printf" 15 | x="${ary[*]}" # segfaults here 16 | echo "after use: $?" 17 | -------------------------------------------------------------------------------- /tests/run-trap: -------------------------------------------------------------------------------- 1 | echo "warning: UNIX versions number signals and schedule processes differently." >&2 2 | echo "warning: If output differing only in line numbers is produced, please" >&2 3 | echo "warning: do not consider this a test failure." >&2 4 | 5 | ${THIS_SH} ./trap.tests > ${BASH_TSTOUT} 2>&1 6 | diff ${BASH_TSTOUT} trap.right && rm -f ${BASH_TSTOUT} 7 | -------------------------------------------------------------------------------- /tests/case.right: -------------------------------------------------------------------------------- 1 | fallthrough 2 | to here 3 | and here 4 | retest 5 | and match 6 | no more clauses 7 | 1.0 8 | ./case.tests: line 29: xx: readonly variable 9 | 1.1 10 | matches 1 11 | no 12 | no 13 | no 14 | no 15 | no 16 | ok 17 | ok 1 18 | ok 2 19 | ok 3 20 | ok 4 21 | ok 5 22 | ok 6 23 | ok 7 24 | ok 8 25 | ok 9 26 | mysterious 1 27 | mysterious 2 28 | -------------------------------------------------------------------------------- /tests/exec9.sub: -------------------------------------------------------------------------------- 1 | # make sure commands before the last one in the pipeline can't change $? 2 | false 3 | false | echo $? 4 | false 5 | (false) | echo $? 6 | 7 | false 8 | true | echo $? 9 | false 10 | (true) | echo $? 11 | 12 | true 13 | false | echo $? 14 | true 15 | (false) | echo $? 16 | 17 | true 18 | true | echo $? 19 | true 20 | (true) | echo $? 21 | -------------------------------------------------------------------------------- /tests/histexp4.sub: -------------------------------------------------------------------------------- 1 | HISTFILE=$TMPDIR/bashhist-$$ 2 | 3 | set -o history 4 | set -o histexpand 5 | 6 | echo a 7 | cat < <(echo !!) 8 | 9 | echo b 10 | echo !! `echo !!` 11 | 12 | echo c 13 | echo "$(echo "!" )" 14 | 15 | echo d 16 | echo "$(echo '!' )" 17 | 18 | echo e 19 | echo '!' "!" 20 | echo "'!'" 21 | 22 | set +o history 23 | rm -f $HISTFILE 24 | -------------------------------------------------------------------------------- /tests/run-heredoc: -------------------------------------------------------------------------------- 1 | echo "warning: UNIX versions number signals and schedule processes differently." >&2 2 | echo "warning: If output differing only in line numbers is produced, please" >&2 3 | echo "warning: do not consider this a test failure." >&2 4 | 5 | ${THIS_SH} ./heredoc.tests > ${BASH_TSTOUT} 2>&1 6 | diff ${BASH_TSTOUT} heredoc.right && rm -f ${BASH_TSTOUT} 7 | -------------------------------------------------------------------------------- /lib/malloc/i386-alloca.s: -------------------------------------------------------------------------------- 1 | .file "alloca.s" 2 | .text 3 | .align 4 4 | .def alloca; .val alloca; .scl 2; .type 044; .endef 5 | .globl alloca 6 | alloca: 7 | popl %edx 8 | popl %eax 9 | addl $3,%eax 10 | andl $0xfffffffc,%eax 11 | subl %eax,%esp 12 | movl %esp,%eax 13 | pushl %eax 14 | pushl %edx 15 | ret 16 | .def alloca; .val .; .scl -1; .endef 17 | -------------------------------------------------------------------------------- /tests/assoc2.sub: -------------------------------------------------------------------------------- 1 | echo ${BASH_ALIASES[@]} 2 | 3 | alias foo=/usr/sbin/foo 4 | alias qux='/usr/local/bin/qux -l' 5 | 6 | echo ${!BASH_ALIASES[@]} 7 | recho ${BASH_ALIASES[@]} 8 | 9 | BASH_ALIASES[blat]='cd /blat ; echo $PWD' 10 | BASH_ALIASES[sh]='/bin/bash --login -o posix' 11 | 12 | alias -p 13 | 14 | echo ${!BASH_ALIASES[@]} 15 | recho "${BASH_ALIASES[@]}" 16 | -------------------------------------------------------------------------------- /tests/read1.sub: -------------------------------------------------------------------------------- 1 | a=7 2 | echo 'abcdefg|xyz' | { 3 | read -d '|' a 4 | echo a = "${a-unset}" 5 | } 6 | 7 | echo xyz 123 | { 8 | read -d ' ' a 9 | echo a = "${a-unset}" 10 | } 11 | 12 | echo xyz 123 | { 13 | read -d $'\n' a 14 | echo a = -"${a-unset}"- 15 | } 16 | 17 | a=44 18 | echo abcd | { 19 | read -d d a 20 | echo a = $a 21 | } 22 | 23 | exit 0 24 | -------------------------------------------------------------------------------- /tests/dollar-star3.sub: -------------------------------------------------------------------------------- 1 | IFS=/ 2 | #file=/mnt/cdrom/RedHat/RPMS 3 | #recho "${file[*]:0:3}" 4 | 5 | i[0]=fooq 6 | i[1]= 7 | i[2]=barq 8 | i[3]= 9 | recho "${i[*]:0}" 10 | recho "${i[@]:0}" 11 | 12 | recho "${i[*]/q/!}" 13 | recho "${i[@]/q/!}" 14 | 15 | recho "${i[*]#?}" 16 | recho "${i[@]#?}" 17 | 18 | # Need to complete this with case-modifying expansion examples 19 | -------------------------------------------------------------------------------- /tests/globstar1.sub: -------------------------------------------------------------------------------- 1 | shopt -s globstar 2 | wdir=$PWD 3 | 4 | : ${TMPDIR:=/var/tmp} 5 | DIR=$TMPDIR/globstar-$$ 6 | mkdir -p $DIR 7 | cd $DIR || { 8 | echo "$DIR: cannot cd" >&2 9 | exit 1 10 | } 11 | mkdir -p foo/{a,b} bar/{c,d,foo/{e,f}} baz/{g,h} 12 | 13 | 14 | echo **/foo* 15 | 16 | echo **/foo*/ 17 | 18 | echo **/foo*/* 19 | 20 | cd $wdir 21 | rm -rf $DIR 22 | -------------------------------------------------------------------------------- /tests/histexp1.sub: -------------------------------------------------------------------------------- 1 | LC_ALL=C 2 | LANG=C 3 | 4 | set -o history 5 | set -H 6 | 7 | echo '!' 8 | echo "!" 9 | echo ! 10 | 11 | echo "$( echo '!' )" 12 | echo "$( echo "!" )" 13 | echo "$( echo ! )" 14 | 15 | echo $( echo '!' ) 16 | echo $( echo "!" ) 17 | echo $( echo ! ) 18 | 19 | echo "$( echo "\!" )" 20 | echo "\!" 21 | 22 | echo "$( echo '\!' )" 23 | echo '\!' 24 | -------------------------------------------------------------------------------- /tests/redir3.sub: -------------------------------------------------------------------------------- 1 | read line1 2 | 3 | echo read line1 \"$line1\" 4 | 5 | exec 4<./redir3.in2 6 | 7 | exec 5<&0 8 | exec 0<&4 9 | 10 | read line2 11 | 12 | echo read line2 \"$line2\" 13 | 14 | exec 0<&5 15 | 16 | read line3 17 | 18 | echo read line3 \"$line3\" 19 | 20 | exec 0<&4 21 | 22 | read line4 23 | 24 | echo read line4 \"$line4\" 25 | 26 | exec 4<&- 27 | -------------------------------------------------------------------------------- /tests/array7.sub: -------------------------------------------------------------------------------- 1 | # these didn't work in versions of bash before bash-4.0 2 | 3 | LNAME=nordholz 4 | 5 | echo ${LNAME[$(( 0 ))]//h/!} 6 | echo ${LNAME[$(( 2 ))]//h/!} 7 | 8 | echo ${LNAME[$(( 0 ))]##??} 9 | echo ${LNAME[$(( 2 ))]##??} 10 | 11 | echo ${LNAME[$(( 0 ))]:2} 12 | echo ${LNAME[$(( 0 ))]:2:4} 13 | echo ${LNAME[$(( 2 ))]:2} 14 | echo ${LNAME[$(( 2 ))]:2:4} 15 | -------------------------------------------------------------------------------- /tests/extglob3.right: -------------------------------------------------------------------------------- 1 | match 1 2 | match 2 3 | match 3 4 | match 4 5 | match 1a 6 | match 1b 7 | match 2a 8 | match 2b 9 | match 3a 10 | match 3b 11 | match 4a 12 | match 4b 13 | match 5 14 | match 6 15 | match 7 16 | match 8 17 | match 9 18 | match 10 19 | match 11 20 | match 12 21 | match 13 22 | match 14 23 | match 15 24 | match 16 25 | match 17 26 | match 18 27 | ok 19 28 | -------------------------------------------------------------------------------- /tests/run-intl: -------------------------------------------------------------------------------- 1 | # See whether or not we can use `diff -a' 2 | ( diff -a ./intl.right ./intl.right >/dev/null 2>&1 ) && AFLAG=-a 3 | 4 | echo "warning: some of these tests will fail if you do not have UTF-8" >&2 5 | echo "warning: locales installed on your system." >&2 6 | 7 | ${THIS_SH} ./intl.tests > ${BASH_TSTOUT} 8 | diff $AFLAG ${BASH_TSTOUT} intl.right && rm -f ${BASH_TSTOUT} 9 | -------------------------------------------------------------------------------- /tests/run-set-x: -------------------------------------------------------------------------------- 1 | #!../bash 2 | #$Id: run-set-x,v 1.1 2002/12/09 13:12:37 rockyb Exp $ 3 | 4 | TEST_NAME='set-x' 5 | TEST_FILE="/tmp/${TEST_NAME}.check" 6 | ${THIS_SH} ./${TEST_NAME}.tests > $TEST_FILE 2>&1 < /dev/null 7 | set -f 8 | diff $TEST_FILE ${TEST_NAME}.right && rm -f $TEST_FILE 9 | 10 | # Return code tells testing mechanism whether passed or not. 11 | exit $? 12 | -------------------------------------------------------------------------------- /tests/alias2.sub: -------------------------------------------------------------------------------- 1 | THIS=alias2 2 | FN=$TMPDIR/$THIS.script 3 | 4 | cat > $FN <<'EOF' 5 | # 6 | (echo "$1") 7 | EOF 8 | chmod u+x $FN 9 | 10 | shopt -s expand_aliases 11 | 12 | alias foo1='$FN one; source $FN two; source $FN three; $FN four' 13 | 14 | alias foo2='$FN one 15 | source $FN two 16 | source $FN three 17 | $FN four' 18 | 19 | foo1 20 | foo2 21 | 22 | rm -f $FN 23 | -------------------------------------------------------------------------------- /examples/functions/fact: -------------------------------------------------------------------------------- 1 | # Who said shells can't use recursion? Here is a factorial function. 2 | # You call it with a number as an argument, and it returns the factorial 3 | # of that number. 4 | 5 | fact () 6 | { 7 | local num=$1; 8 | if [ "$num" = 1 ] ; then 9 | echo 1 10 | return ; 11 | fi; 12 | echo $(( $num * $(fact $(( $num - 1 )) ) )) 13 | } 14 | -------------------------------------------------------------------------------- /tests/run-jobs: -------------------------------------------------------------------------------- 1 | echo "warning: some of these tests may fail if job control has not been compiled" >&2 2 | echo "warning: into the shell" >&2 3 | echo "warning: there may be a message regarding a cat process dying due to a" >&2 4 | echo "warning: SIGHUP. Please disregard." >&2 5 | 6 | ${THIS_SH} ./jobs.tests > ${BASH_TSTOUT} 2>&1 7 | diff ${BASH_TSTOUT} jobs.right && rm -f ${BASH_TSTOUT} 8 | -------------------------------------------------------------------------------- /examples/functions/isvalidip: -------------------------------------------------------------------------------- 1 | # Thanks to Chris F. A. Johnson for this one 2 | is_validip() 3 | { 4 | case "$*" in 5 | ""|*[!0-9.]*|*[!0-9]) return 1 ;; 6 | esac 7 | 8 | local IFS=. 9 | set -- $* 10 | 11 | [ $# -eq 4 ] && 12 | [ ${1:-666} -le 255 ] && [ ${2:-666} -le 255 ] && 13 | [ ${3:-666} -le 255 ] && [ ${4:-666} -le 254 ] 14 | } 15 | -------------------------------------------------------------------------------- /tests/exec11.sub: -------------------------------------------------------------------------------- 1 | trap 'echo USR1 $BASHPID' USR1 2 | trap 'echo foo $BASH_SUBSHELL' 0 3 | 4 | trap | cat 5 | echo between 6 | ( trap ) 7 | echo between 2 8 | { trap; } | cat 9 | 10 | ( echo in subshell: $BASH_SUBSHELL ) 11 | ( echo in subshell pipeline: $BASH_SUBSHELL ) | cat 12 | 13 | { echo group pipeline: $BASH_SUBSHELL; 14 | trap 'echo EXIT-group.$BASH_SUBSHELL' EXIT; } | cat 15 | -------------------------------------------------------------------------------- /tests/run-array: -------------------------------------------------------------------------------- 1 | echo "warning: all of these tests will fail if arrays have not" >&2 2 | echo "warning: been compiled into the shell" >&2 3 | echo "warning: the BASH_ARGC and BASH_ARGV tests will fail if debugging support" >&2 4 | echo "warning: has not been compiled into the shell" >&2 5 | ${THIS_SH} ./array.tests > ${BASH_TSTOUT} 2>&1 6 | diff ${BASH_TSTOUT} array.right && rm -f ${BASH_TSTOUT} 7 | -------------------------------------------------------------------------------- /tests/run-dbg-support: -------------------------------------------------------------------------------- 1 | #!../bash 2 | #$Id: run-dbg-support,v 1.5 2002/11/14 06:08:16 rockyb Exp $ 3 | 4 | TEST_NAME='dbg-support' 5 | TEST_FILE="/tmp/${TEST_NAME}.check" 6 | ${THIS_SH} ./${TEST_NAME}.tests > $TEST_FILE 2>&1 < /dev/null 7 | set -f 8 | diff $TEST_FILE ${TEST_NAME}.right && rm -f $TEST_FILE 9 | 10 | # Return code tells testing mechanism whether passed or not. 11 | exit $? 12 | -------------------------------------------------------------------------------- /tests/trap2.sub: -------------------------------------------------------------------------------- 1 | set +e 2 | trap 'echo ERRTRAP' ERR 3 | 4 | false 5 | false 6 | false 7 | 8 | echo after falses 9 | 10 | if ! false; then 11 | echo if negation ok 12 | fi 13 | 14 | ! false 15 | echo after negation 16 | 17 | while false; do 18 | echo while negation ok 19 | done 20 | 21 | echo after while 22 | 23 | ./trap2a.sub 24 | 25 | echo $(false ; echo command substitution) 26 | -------------------------------------------------------------------------------- /tests/alias1.sub: -------------------------------------------------------------------------------- 1 | shopt -s expand_aliases 2 | 3 | alias foo=echo 4 | 5 | < /dev/null foo bar 6 | 7 | < /dev/null x=value 8 | echo $x 9 | 10 | < /dev/null x=newvalue foo bar 11 | echo $x 12 | 13 | # problem reported by Vincent Lefevre 14 | alias a="echo OK >&2" 15 | a 16 | > /dev/null a 17 | 18 | ${THIS_SH} -c 'shopt -s expand_aliases; alias a="echo OK >&2" 19 | a 20 | > /dev/null a' 21 | -------------------------------------------------------------------------------- /tests/run-printf: -------------------------------------------------------------------------------- 1 | # See whether or not we can use `diff -a' 2 | #( diff -a ./printf.tests ./printf.tests >/dev/null 2>&1 ) && AFLAG=-a 3 | 4 | # use cat -v (and assume it's there) to make control chars visible 5 | ${THIS_SH} ./printf.tests 2>&1 | cat -v > ${BASH_TSTOUT} 6 | #diff $AFLAG ${BASH_TSTOUT} printf.right && rm -f ${BASH_TSTOUT} 7 | diff ${BASH_TSTOUT} printf.right && rm -f ${BASH_TSTOUT} 8 | -------------------------------------------------------------------------------- /tests/source5.sub: -------------------------------------------------------------------------------- 1 | LC_ALL=en_US.UTF-8 2 | unset LC_ALL 3 | unset LANG 4 | export LC_ALL=C 5 | export LANG=C 6 | 7 | set +o posix 8 | 9 | # attempting to source a non-existant file is not an error... 10 | . /tmp/source-notthere 11 | 12 | echo after bad source 1 13 | 14 | set -o posix 15 | 16 | # ...unless you're in posix mode 17 | . /tmp/source-notthere 18 | 19 | echo after bad source 2 20 | -------------------------------------------------------------------------------- /tests/run-cond: -------------------------------------------------------------------------------- 1 | echo "warning: all of these tests will fail if the conditional command has not" >&2 2 | echo "warning: been compiled into the shell" >&2 3 | echo "warning: some of these tests will fail if extended pattern matching has not" >&2 4 | echo "warning: been compiled into the shell" >&2 5 | 6 | ${THIS_SH} ./cond.tests > ${BASH_TSTOUT} 2>&1 7 | diff ${BASH_TSTOUT} cond.right && rm -f ${BASH_TSTOUT} 8 | -------------------------------------------------------------------------------- /tests/set-x.tests: -------------------------------------------------------------------------------- 1 | #!../bash 2 | # $Id: set-x.tests,v 1.1 2002/12/09 13:12:37 rockyb Exp $ 3 | # 4 | # Test that "set -x" shows what we think it should. 5 | # 6 | set -x 7 | for ((i=0; i<=5; i++ )) ; do 8 | x=0 9 | done 10 | for i in 0 1 2 ; do 11 | x=i 12 | done 13 | case x in 14 | 0) x=i ;; 15 | *) x=i ;; 16 | esac 17 | set +x 18 | 19 | # test BASH_XTRACEFD 20 | ${THIS_SH} ./set-x1.sub 21 | -------------------------------------------------------------------------------- /examples/scripts/inpath: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # Search $PATH for a file the same name as $1; return TRUE if found. 4 | # 5 | 6 | command=$1 7 | [ -n "$command" ] || exit 1 8 | 9 | set `echo $PATH | sed 's/^:/.:/ 10 | s/::/:.:/g 11 | s/:$/:./ 12 | s/:/ /g'` 13 | 14 | while [ $# -ne 0 ] ; do 15 | [ -f $1/$command ] && exit 0 # test -x not universal 16 | shift 17 | done 18 | 19 | exit 1 20 | -------------------------------------------------------------------------------- /tests/exec12.sub: -------------------------------------------------------------------------------- 1 | : ${TMPDIR:=/var/tmp} 2 | TMPFILE=$TMPDIR/exitcode 3 | 4 | rm -f $TMPFILE 5 | set -e 6 | exit_handler() { echo "exit code: $?" ; touch $TMPFILE; } 7 | false() { ! :; } 8 | notfound() { nosuchcommand ; } 9 | syntaxerror() { !:; } 10 | 11 | main() 12 | {( 13 | trap exit_handler 0 14 | "$@" >> /dev/null 2>&1 15 | )} 16 | main "$@" 17 | echo "after main: should not get here" 18 | -------------------------------------------------------------------------------- /tests/posix2.right: -------------------------------------------------------------------------------- 1 | Testing for POSIX.2 conformance 2 | ./posix2.tests: eval: line 182: syntax error near unexpected token `esac' 3 | ./posix2.tests: eval: line 182: `case esac in (esac) ;; *) echo "case esac test 3" ;; esac' 4 | ./posix2.tests: eval: line 184: syntax error near unexpected token `)' 5 | ./posix2.tests: eval: line 184: `case esac in esac) ;; *) echo "case esac test 4";; esac' 6 | All tests passed 7 | -------------------------------------------------------------------------------- /tests/array9.sub: -------------------------------------------------------------------------------- 1 | echo $(( 0x7e )) 2 | echo $(( 0x7f )) 3 | echo $(( 0x80 )) 4 | 5 | a=$'\x80' 6 | recho "$a" 7 | 8 | a=( $'\x7e' $'\x7f' $'\x80' ) 9 | 10 | recho "${a[@]}" 11 | 12 | unset a 13 | a[0]=$'\x7e' 14 | a[1]=$'\x7f' 15 | a[2]=$'\x80' 16 | 17 | recho "${a[@]}" 18 | 19 | b1=$'\x7e' 20 | b2=$'\x7f' 21 | b3=$'\x80' 22 | 23 | unset a 24 | a=( "$b1" "$b2" "$b3" ) 25 | 26 | recho "${a[@]}" 27 | 28 | -------------------------------------------------------------------------------- /tests/COPYRIGHT: -------------------------------------------------------------------------------- 1 | Unless otherwise stated, all files in this directory are Copyright (C) 2 | 1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003, 3 | 2004,2005,2006,2007,2008,2009,2010,2011 4 | Free Software Foundation, Inc. 5 | 6 | See the file COPYING in the bash distribution root directory for copying 7 | and usage restrictions. 8 | 9 | The file ifs-posix.tests is Copyright (C) 2005 Glen Fowler. 10 | -------------------------------------------------------------------------------- /tests/dollar-at-star8.sub: -------------------------------------------------------------------------------- 1 | function f { 2 | typeset -a a 3 | a=("$@") 4 | typeset IFS=, 5 | typeset a1="${a[@]} ${a[*]} $@ $* ${@} ${*}" 6 | typeset a2=${a[@]}\ ${a[*]}\ $@\ $*\ ${@}\ ${*} a3 a4 7 | a3="${a[@]} ${a[*]} $@ $* ${@} ${*}" 8 | a4=${a[@]}\ ${a[*]}\ $@\ $*\ ${@}\ ${*} 9 | unset -v IFS 10 | printf '%s\n' "a1=$a1" "a2=$a2" "a3=$a3" "a4=$a4" 11 | } 12 | 13 | echo 14 | f a b c 15 | -------------------------------------------------------------------------------- /tests/func2.sub: -------------------------------------------------------------------------------- 1 | funca() ( 2 | echo func-a 3 | ) 4 | 5 | funcb() ( echo func-b ) 6 | 7 | funcc() ( 8 | echo func-c 9 | ) 2>&1 10 | 11 | type funca 12 | type funcb 13 | type funcc 14 | 15 | funca 16 | funcb 17 | funcc 18 | 19 | # when not in posix mode, bash allows non-identifiers as function names 20 | set +o posix 21 | foo-bar() 22 | { 23 | :; 24 | } 25 | 26 | declare -F foo-bar 27 | declare -f foo-bar 28 | -------------------------------------------------------------------------------- /tests/set-x1.sub: -------------------------------------------------------------------------------- 1 | : ${TMPDIR:=/var/tmp} 2 | TRACEFILE=$TMPDIR/bash-trace-$$ 3 | trap 'rm -f $TRACEFILE' 0 1 2 3 6 15 4 | 5 | exec 4>$TRACEFILE 6 | BASH_XTRACEFD=4 7 | 8 | set -x 9 | 10 | echo 1 11 | echo 2 12 | echo 3 13 | echo 4 14 | 15 | unset BASH_XTRACEFD 16 | 17 | for f in a b c d e; do echo $f ; done 18 | 19 | set +x 20 | 21 | echo TRACEFILE: 22 | cat $TRACEFILE 23 | echo ===== 24 | 25 | exit 0 26 | -------------------------------------------------------------------------------- /tests/tilde2.right: -------------------------------------------------------------------------------- 1 | PATH=~/bin:/bin:/usr/bin:. 2 | /usr/xyz/bin:~/bin2:/bin:/usr/bin:. 3 | PATH=~/bin:~/bin2:/bin:/usr/bin:. 4 | ~/bin 5 | ~ 6 | /usr/xyz 7 | ~ 8 | ~ 9 | ~ 10 | argv[1] = <\a> 11 | argv[1] = <\a> 12 | /usr/xyz/bash 13 | ok 14 | ~ 15 | ~ 16 | make -k FOO=/usr/xyz/mumble 17 | /usr/xyz/mumble 18 | HOME=~ 19 | HOME=~ 20 | /usr/$x/abc 21 | HOME=~ 22 | /usr/$x/abc 23 | HOME=/usr/$x/abc 24 | /usr/$x/abc 25 | -------------------------------------------------------------------------------- /tests/assoc4.sub: -------------------------------------------------------------------------------- 1 | IFS=/ 2 | declare -A i 3 | 4 | i[0]=fooq 5 | i[1]= 6 | i[2]=barq 7 | i[3]= 8 | 9 | recho "${i[*]:0}" 10 | recho "${i[@]:0}" 11 | 12 | recho "${i[*]/q/!}" 13 | recho "${i[@]/q/!}" 14 | 15 | recho "${i[*]#?}" 16 | recho "${i[@]#?}" 17 | 18 | # Need to complete this with case-modifying expansion examples 19 | recho "${i[*]^?}" 20 | recho "${i[@]^?}" 21 | recho "${i[*]^^?}" 22 | recho "${i[@]^^?}" 23 | -------------------------------------------------------------------------------- /tests/exp5.sub: -------------------------------------------------------------------------------- 1 | # expansions involving patterns 2 | 3 | var='[hello' 4 | echo "${var//[/}" 5 | 6 | red='\[\e[0;31m\]' 7 | echo "${red//\\[\\e/}" 8 | 9 | foo="${red//\\[\\e/}" 10 | 11 | # foo == [0;31m\] 12 | echo "${foo//[0;31m\\/}" 13 | 14 | echo "${var//[]/}" 15 | echo "${red//[]/}" 16 | 17 | v=hello 18 | foo='[:alpha:]' 19 | 20 | echo ${v//[[:alpha:]]/} 21 | echo ${v//[[:alpha]]/} 22 | echo ${v//[[:alpha]/} 23 | -------------------------------------------------------------------------------- /tests/read3.sub: -------------------------------------------------------------------------------- 1 | # non-interactive 2 | 3 | # error 4 | read -n -1 5 | 6 | # from pipe -- should work, but doesn't change tty attributes 7 | echo abcdefg | { 8 | read -n 3 xyz 9 | echo $xyz 10 | } 11 | 12 | # fewer chars than specified 13 | echo ab | { 14 | read -n 3 xyz 15 | echo $xyz 16 | } 17 | 18 | echo abc | { 19 | read -N 4 -d$'\n' foo 20 | echo $foo 21 | } 22 | 23 | read -n 1 < $0 24 | echo "$REPLY" 25 | -------------------------------------------------------------------------------- /tests/array8.sub: -------------------------------------------------------------------------------- 1 | IFS=/ 2 | declare -a i 3 | 4 | i[0]=fooq 5 | i[1]= 6 | i[2]=barq 7 | i[3]= 8 | recho "${i[*]:0}" 9 | recho "${i[@]:0}" 10 | 11 | recho "${i[*]/q/!}" 12 | recho "${i[@]/q/!}" 13 | 14 | recho "${i[*]#?}" 15 | recho "${i[@]#?}" 16 | 17 | # Need to complete this with case-modifying expansion examples 18 | recho "${i[*]^?}" 19 | recho "${i[@]^?}" 20 | 21 | recho "${i[*]^^?}" 22 | recho "${i[@]^^?}" 23 | 24 | -------------------------------------------------------------------------------- /tests/mapfile.data: -------------------------------------------------------------------------------- 1 | [0] Abcdefghijklmnop 2 | [1] aBcdefghijklmnop 3 | [2] abCdefghijklmnop 4 | [3] abcDefghijklmnop 5 | [4] abcdEfghijklmnop 6 | [5] abcdeFghijklmnop 7 | [6] abcdefGhijklmnop 8 | [7] abcdefgHijklmnop 9 | [8] abcdefghIjklmnop 10 | [9] abcdefghiJklmnop 11 | [a] abcdefghijKlmnop 12 | [b] abcdefghijkLmnop 13 | [c] abcdefghijklMnop 14 | [d] abcdefghijklmNop 15 | [e] abcdefghijklmnOp 16 | [f] abcdefghijklmnoP 17 | a -------------------------------------------------------------------------------- /tests/redir10.sub: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Out of file descriptors, because it forgets to close redirection. Only 4 | # happens in a shell function. Problem through bash-4.2. 5 | 6 | ulimit -n 128 7 | 8 | bug() 9 | { 10 | c=`ulimit -n` 11 | let c+=100 12 | while let c-- 13 | do 14 | while read -ru3 x 15 | do 16 | echo -n : 17 | done 3< <(echo x) 18 | 19 | done 20 | } 21 | 22 | bug 23 | echo 24 | 25 | exit 0 26 | -------------------------------------------------------------------------------- /tests/dollar-at-star1.sub: -------------------------------------------------------------------------------- 1 | # from dan douglas 2 | expassign() 3 | { 4 | typeset -a a 5 | a=("$@") 6 | typeset var asn 7 | 8 | while IFS= read -r asn; do 9 | IFS=: command eval "$asn" 10 | printf '%-14s... %s\n' "$asn" "$var" 11 | done <<\EOF 12 | var=${a[*]} 13 | var="${a[*]}" 14 | var=$* 15 | var="$*" 16 | var=${a[@]} 17 | var="${a[@]}" 18 | var=$@ 19 | var="$@" 20 | EOF 21 | } 22 | 23 | expassign one:::two three:::four 24 | -------------------------------------------------------------------------------- /tests/herestr1.sub: -------------------------------------------------------------------------------- 1 | # problems with word splitting unquoted here-strings present since bash-3.2 2 | 3 | x="foo bar" 4 | cat <<< $x # Word-splitting appears to collapse the run of whitespace 5 | cat <<< "$x" # Whitespace preserved, as with here doc 6 | 7 | x="qux:::::bax" 8 | IFS=':' 9 | cat <<< $x # Word-splitting appears to collapse the run of whitespace 10 | cat <<< "$x" # Whitespace preserved, as with here doc 11 | -------------------------------------------------------------------------------- /tests/varenv6.sub: -------------------------------------------------------------------------------- 1 | f() 2 | { 3 | local str=F 4 | g str 5 | } 6 | 7 | g() 8 | { 9 | local -n ref=$1 10 | printf "%s " "$ref" 11 | ref=G 12 | } 13 | 14 | str=OUTSIDE; 15 | f 16 | 17 | printf "%s\n" "$str" 18 | 19 | unset -f f g 20 | unset str 21 | 22 | f() { local -a arr=(F); g arr; }; 23 | 24 | g() { local -n ref=$1; printf "%s " "${ref[0]}"; ref=(G); }; 25 | 26 | arr=(OUTSIDE); 27 | f; 28 | printf "%s\n" "${arr[0]}" 29 | -------------------------------------------------------------------------------- /CWRU/sh-redir-hack: -------------------------------------------------------------------------------- 1 | Add to `subshell' production in parse.y and recompile -DREDIRECTION_HACK to 2 | get `< xx (command)' sh compatibility. 3 | 4 | | redirections '(' list ')' 5 | { 6 | #if defined (REDIRECTION_HACK) 7 | /* XXX - C News sh compatibility hack - XXX */ 8 | $3->redirects = $1; 9 | $3->flags |= CMD_WANT_SUBSHELL; 10 | $$ = $3; 11 | #else 12 | yyerror (); 13 | YYABORT; 14 | #endif 15 | } 16 | -------------------------------------------------------------------------------- /examples/functions/array-to-string: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # Format: array_to_string vname_of_array vname_of_string separator 4 | array_to_string() 5 | { 6 | (( ($# < 2) || ($# > 3) )) && { 7 | "$FUNCNAME: usage: $FUNCNAME arrayname stringname [separator]" 8 | return 2 9 | } 10 | 11 | local array=$1 string=$2 12 | ((3==$#)) && [[ $3 = ? ]] && local IFS="${3}${IFS}" 13 | eval $string="\"\${$array[*]}\"" 14 | return 0 15 | } 16 | -------------------------------------------------------------------------------- /tests/dollar-at1.sub: -------------------------------------------------------------------------------- 1 | echo_argc() 2 | { 3 | echo $# 4 | } 5 | 6 | a() 7 | { 8 | shift 9 | echo_argc "$@" 10 | echo_argc ${1:+"$@"} 11 | echo_argc "${1:+$@}" 12 | echo_argc 1 2 3 13 | } 14 | 15 | b() 16 | { 17 | _IFS="$IFS" 18 | IFS="$1" 19 | shift 20 | echo_argc "$@" 21 | echo_argc ${1:+"$@"} 22 | echo_argc "${1:+$@}" 23 | echo_argc 1 2 3 24 | IFS="$_IFS" 25 | } 26 | 27 | a "X" foo bar hoge 28 | 29 | b "X" foo bar hoge 30 | -------------------------------------------------------------------------------- /tests/dstack2.right: -------------------------------------------------------------------------------- 1 | expect ~1 2 | ~1 3 | /usr / 4 | /tmp /usr / 5 | /tmp /usr / 6 | these lines should be the same 7 | /tmp 8 | /tmp /tmp 9 | these lines should be the same 10 | /usr 11 | /usr /usr 12 | these lines should be the same 13 | / 14 | / / 15 | these lines should be the same 16 | /tmp 17 | /tmp /tmp 18 | these lines should be the same 19 | /usr 20 | /usr /usr 21 | 1 /usr 22 | these lines should be the same 23 | / 24 | / / 25 | -------------------------------------------------------------------------------- /tests/redir5.sub: -------------------------------------------------------------------------------- 1 | # tests of ksh93-like dup-and-close redirection operators 2 | exec 9<$0 3 | 4 | f() 5 | { 6 | exec 5<$0 7 | 8 | exec 0<&5- 9 | 10 | while read line; do 11 | echo "$line" 12 | done 13 | } 14 | 15 | f 16 | 17 | typeset -f f 18 | 19 | # make sure it was closed 20 | read -u 5 foo 21 | echo after read 22 | 23 | exec 5<&0 24 | 25 | exec <&- 26 | 27 | read abcde 28 | 29 | exec 0<&9- 30 | read line 31 | echo $line 32 | -------------------------------------------------------------------------------- /examples/startup-files/Bash_profile: -------------------------------------------------------------------------------- 1 | # Startup file for bash login shells. 2 | # 3 | default_dir=/usr/local/lib/ 4 | 5 | if [ -n "$PS1" ]; then 6 | PS1='\u@\h(\#)\$ ' 7 | IGNOREEOF=3 8 | fi 9 | 10 | LOGIN_SHELL=true 11 | 12 | # If the user has her own init file, then use that one, else use the 13 | # canonical one. 14 | if [ -f ~/.bashrc ]; then 15 | . ~/.bashrc 16 | elif [ -f ${default_dir}Bashrc ]; then 17 | . ${default_dir}Bashrc; 18 | fi 19 | -------------------------------------------------------------------------------- /tests/nquote4.tests: -------------------------------------------------------------------------------- 1 | recho $'ab\x{}cd' 2 | recho $'ab\x{41}cd' 3 | recho $'ab\x41cd' 4 | 5 | recho $'ab\x{4}cd' 6 | recho $'ab\x4cd' 7 | 8 | recho $'ab\x{cde' 9 | 10 | recho $'ab\x{cde' 11 | recho $'ab\x{cd}e' 12 | recho $'ab\x{c}de' 13 | 14 | recho $'\x{abcX' 15 | recho $'\x{ab}cX' 16 | recho $'\x{}X' 17 | recho $'\x{X' 18 | recho $'\x{01234567X' 19 | 20 | recho $'\x{41}b' 21 | recho $'\x{}bc' 22 | recho $'\x{1}bcd' 23 | 24 | recho $'\x{bde' 25 | -------------------------------------------------------------------------------- /tests/posixpat.right: -------------------------------------------------------------------------------- 1 | ok 1 2 | ok 2 3 | ok 3 4 | ok 4 5 | ok 5 6 | ok 6 7 | ok 7 8 | ok 8 9 | ok 9 10 | ok 10 11 | ok 11 12 | ok 12 13 | ok 13 14 | ok 14 15 | ok 15 16 | ok 16 17 | ok 17 18 | ok 18 19 | ok 19 20 | ok 20 21 | ok 21 22 | ok -- space 23 | ok -- blank 24 | ok 1 25 | ok 2 26 | ok 3 27 | ok 4 28 | ok 5 29 | ok 6 30 | ok 7 31 | ok 8 32 | ok 9 33 | ok 10 34 | ok 11 35 | ok 12 36 | ok 13 37 | ok 14 38 | ok 15 39 | ok 16 40 | ok 1 41 | ok 2 42 | ok 3 43 | -------------------------------------------------------------------------------- /tests/dollar-at-star6.sub: -------------------------------------------------------------------------------- 1 | OIFS="$IFS" 2 | arr=(a b c) 3 | 4 | recho ${arr[@]@Q} 5 | recho "${arr[@]@Q}" 6 | 7 | IFS="'" 8 | recho ${arr[@]@Q} 9 | recho "${arr[@]@Q}" 10 | IFS="$OIFS" 11 | 12 | arr=("'a'" "'b'" "'c'") 13 | 14 | IFS="'" 15 | recho ${arr[@]} 16 | recho "${arr[@]}" 17 | IFS="$OIFS" 18 | 19 | IFS="'" 20 | a="'a'" 21 | recho $a 22 | recho "$a" 23 | IFS="$OIFS" 24 | 25 | set -- "'a'" "'b'" "'c'" 26 | 27 | IFS="'" 28 | recho "${@}" 29 | recho "$@" 30 | -------------------------------------------------------------------------------- /tests/posixpipe.right: -------------------------------------------------------------------------------- 1 | 1 2 | 0 3 | a 4 | real 0.00 5 | user 0.00 6 | sys 0.00 7 | 1 8 | a 9 | real 0.00 10 | user 0.00 11 | sys 0.00 12 | 1 13 | tfunc is a function 14 | tfunc () 15 | { 16 | time 17 | } 18 | 1 19 | 0 20 | 1 21 | a 22 | real 0.00 23 | user 0.00 24 | sys 0.00 25 | 0 26 | a 27 | real 0.00 28 | user 0.00 29 | sys 0.00 30 | 0 31 | a 32 | real 0.00 33 | user 0.00 34 | sys 0.00 35 | 0 36 | 1 37 | 0 38 | a 39 | real 0.00 40 | user 0.00 41 | sys 0.00 42 | -------------------------------------------------------------------------------- /tests/errors4.sub: -------------------------------------------------------------------------------- 1 | # test effect of assigning to readonly vars on loops and non-interactive shells 2 | # fatal error when in posix mode 3 | var=foo 4 | readonly var 5 | for num in 1 2 3 4 5; do 6 | if [ $num -eq 3 ]; then 7 | var=bar 8 | fi 9 | echo $num 10 | done 11 | echo after readonly assignment 12 | 13 | # non-numeric arguments to break are fatal errors for all non-interactive shells 14 | for f in 1 2 3 4 5 15 | do 16 | break x 17 | done 18 | echo after loop 19 | -------------------------------------------------------------------------------- /tests/exportfunc3.sub: -------------------------------------------------------------------------------- 1 | # test function names that cannot be exported 2 | 3 | unset foo # remove from environment if necessary 4 | 5 | function foo=bar 6 | { 7 | echo equals-1 8 | } 9 | 10 | export -f 'foo=bar' 11 | echo status: $? 12 | 13 | foo\=bar 14 | printenv | grep 'foo=bar' 15 | ${THIS_SH} -c 'foo\=bar 2>/dev/null' 16 | 17 | function /bin/echo 18 | { 19 | echo bad echo 20 | } 21 | 22 | /bin/echo foo 23 | export -f '/bin/echo' 24 | 25 | ${THIS_SH} -c '/bin/echo bar' 26 | -------------------------------------------------------------------------------- /tests/exec13.sub: -------------------------------------------------------------------------------- 1 | echo x1 | ( cat & wait ) 2 | echo x1a | ( :& cat & wait ) 3 | 4 | echo x2 | for f in 1; do 5 | cat & wait 6 | done 7 | echo x2a | if true; then cat & wait; fi 8 | echo x2b | for (( i=0; i < 1; i++ )) ; do cat & wait; done 9 | 10 | echo x3 | { cat & wait; } 11 | 12 | lambda() { cat & wait; } 13 | echo x3a | lambda 14 | 15 | : ${TMPDIR:=/tmp} 16 | SRCF=$TMPDIR/bash-src-$$ 17 | cat > $SRCF << \EOF 18 | cat & wait 19 | EOF 20 | echo x3b | . $SRCF 21 | rm -f $SRCF 22 | -------------------------------------------------------------------------------- /tests/new-exp3.sub: -------------------------------------------------------------------------------- 1 | : 2 | # Set up some dummy variables beginning with _Q 3 | _QUANTITY= 4 | _QUOTA= 5 | _QUOTE= 6 | _QUILL= 7 | _QUEST= 8 | _QUART= 9 | 10 | recho ${!_Q*} 11 | recho ${!_Q@} # compatibility 12 | 13 | IFS="-$IFS" 14 | 15 | recho ${!_Q*} 16 | recho "${!_Q*}" 17 | 18 | recho ${!_Q@} 19 | recho "${!_Q@}" 20 | 21 | recho ${!_Y*} 22 | 23 | recho "${!_Q* }" 24 | 25 | IFS=$' \t\n' 26 | 27 | set a b c d e f g h i j k l m n o p 28 | recho ${!1*} 29 | 30 | recho ${!@*} 31 | -------------------------------------------------------------------------------- /tests/run-redir: -------------------------------------------------------------------------------- 1 | echo "warning: the text of a system error message may vary between systems and" >&2 2 | echo "warning: produce diff output." >&2 3 | echo "warning: if the text of an error message concerning \`redir1.*' not being" >&2 4 | echo "warning: found or messages concerning bad file descriptors produce diff" >&2 5 | echo "warning: output, please do not consider it a test failure" >&2 6 | ${THIS_SH} ./redir.tests > ${BASH_TSTOUT} 2>&1 7 | diff ${BASH_TSTOUT} redir.right && rm -f ${BASH_TSTOUT} 8 | -------------------------------------------------------------------------------- /tests/strip.tests: -------------------------------------------------------------------------------- 1 | v=`echo "" ; echo "" ; echo ""` 2 | echo "'$v'" 3 | v=`echo -n " ab "` 4 | echo "'$v'" 5 | v=`echo -n " "` 6 | echo "'$v'" 7 | v=`echo -n ""` 8 | echo "'$v'" 9 | v=`echo ""` 10 | echo "'$v'" 11 | v=`echo` 12 | echo "'$v'" 13 | v=`echo ababababababab` 14 | echo "'$v'" 15 | v=`echo "ababababababab "` 16 | echo "'$v'" 17 | v=`echo -n "ababababababab "` 18 | echo "'$v'" 19 | v=`echo -ne "abababa\nbababab "` 20 | echo "'$v'" 21 | v="`echo -e '\n\n\n\n'`" 22 | echo "'$v'" 23 | -------------------------------------------------------------------------------- /tests/misc/wait-bg.tests: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | i=0 4 | while [ $i -lt $1 ] 5 | do 6 | /bin/sh -c "sleep 4; exit 0" & 7 | rv=$? 8 | pid=$! 9 | eval bg_pid_$i=$pid 10 | echo $$: Job $i: pid is $pid rv=$rv 11 | i=$((i + 1)) 12 | done 13 | 14 | 15 | 16 | i=0 17 | while [ $i -lt $1 ] 18 | do 19 | eval wpid=\$bg_pid_$i 20 | echo Waiting for job $i '('pid $wpid')' 21 | wait $wpid 22 | rv=$? 23 | echo Return value is $rv 24 | i=$((i + 1)) 25 | done 26 | -------------------------------------------------------------------------------- /tests/tilde.right: -------------------------------------------------------------------------------- 1 | ~chet 2 | /usr/xyz/foo 3 | ~chet/foo 4 | ~chet/foo 5 | ~chet/bar 6 | ~chet/bar 7 | ~chet/bar 8 | :~chet/ 9 | abcd~chet 10 | SHELL=~/bash 11 | /usr/xyz/bash 12 | abcd:~chet 13 | /usr/ucb:/bin:/usr/xyz/bin:/usr/xyz/tmp/bin:/usr/bin 14 | /usr 15 | /tmp 16 | /bin:/usr/bin:.:/usr/xyz/bin 17 | /bin:/usr/bin:.:~/bin 18 | /bin:/usr/bin:.:/usr/xyz/bin 19 | /bin:/usr/bin:.:/usr/xyz/bin 20 | /bin:/usr/bin:.:~/bin 21 | /bin:/usr/bin:.:~/bin 22 | \~ 23 | ok 1 24 | ok 2 25 | ok 3 26 | ~root 27 | -------------------------------------------------------------------------------- /tests/array15.sub: -------------------------------------------------------------------------------- 1 | # fixes for make_internal_declare not handling integer attribute for arrays 2 | declare -ai -g foo=(1 2 xx 3) 3 | echo "${foo[@]}" 4 | 5 | unset foo 6 | declare -ai -g foo='(1 2 xx 3)' 7 | echo "${foo[@]}" 8 | 9 | unset foo 10 | declare -ia -g foo=(1 2 xx 3) 11 | echo "${foo[@]}" 12 | 13 | unset foo 14 | declare -ia -g foo='(1 2 xx 3)' 15 | echo "${foo[@]}" 16 | 17 | unset foo 18 | func() 19 | { 20 | declare -ai -g foo=(1 2 xx 3) 21 | } 22 | 23 | func 24 | echo "${foo[@]}" 25 | -------------------------------------------------------------------------------- /tests/dollar-at-star7.sub: -------------------------------------------------------------------------------- 1 | IFS='' # testing with only empty IFS 2 | 3 | set -- this is a test 4 | 5 | printf '|%s|\n' ${1+"$@"} 6 | echo 7 | printf '|%s|\n' "${1+$@}" 8 | echo 9 | printf '|%s|\n' "$@" 10 | echo 11 | 12 | printf '|%s|\n' ${1-"$@"} 13 | printf '|%s|\n' "${1-$@}" 14 | 15 | echo 16 | : ${foo:="$@"} 17 | printf '|%s|\n' "$foo" 18 | 19 | unset foo 20 | : "${foo:=$@}" 21 | printf '|%s|\n' "$foo" 22 | 23 | unset foo 24 | printf '|%s|\n' ${foo-"$@"} 25 | printf '|%s|\n' "${foo-$@}" 26 | -------------------------------------------------------------------------------- /tests/dollar-star1.sub: -------------------------------------------------------------------------------- 1 | set -- a b c 2 | x=(a b c); IFS='|' 3 | 4 | echo "${*/#/x}" 5 | echo "${x[*]/#/x}" 6 | 7 | echo "$*" 8 | echo "${x[*]}" 9 | 10 | echo "$@" 11 | echo "${x[@]}" 12 | 13 | echo "${@/#/x}" 14 | echo "${x[@]/#/x}" 15 | 16 | echo "${*:1:2}" 17 | echo "${x[*]:1:2}" 18 | 19 | echo "${@:1:2}" 20 | echo "${x[@]:1:2}" 21 | 22 | IFS=$' \t\n' 23 | set -- xa xb xc 24 | x=(xa xb xc) 25 | IFS='|' 26 | 27 | echo "${*#x}" 28 | echo "${x[*]#x}" 29 | 30 | echo "$*" 31 | echo "${x[*]}" 32 | -------------------------------------------------------------------------------- /tests/getopts1.sub: -------------------------------------------------------------------------------- 1 | aflag= 2 | bflag= 3 | 4 | while getopts ab: name 5 | do 6 | case $name in 7 | a) aflag=1 ;; 8 | b) bflag=1 9 | bval=$OPTARG;; 10 | ?) echo Usage: $0 [-a] [-b value] args 11 | exit 2;; 12 | esac 13 | 14 | done 15 | 16 | if [ ! -z "$aflag" ] ; then echo -a specified ; fi 17 | if [ ! -z "$bflag" ] ; then echo -b $bval specified ; fi 18 | 19 | if [ "$OPTIND" -gt 1 ] 20 | then 21 | shift $(( $OPTIND - 1 )) 22 | fi 23 | 24 | echo remaining args: "$*" 25 | 26 | exit 0 27 | -------------------------------------------------------------------------------- /tests/jobs4.sub: -------------------------------------------------------------------------------- 1 | # test being able to use job control notation in jobs/kill/wait without 2 | # job control active, as the SUS requires 3 | 4 | sleep 5 & 5 | 6 | sleep 5 & 7 | sleep 5 & 8 | sleep 5 & 9 | (sleep 5 ; exit 4) & 10 | 11 | jobs 12 | 13 | wait %% 14 | echo $? 15 | 16 | wait %1 17 | echo $? 18 | 19 | wait 20 | 21 | # the sleep is intended to give the kill time to execute before the job 22 | # exits 23 | (sleep 1 ; cat ) & 24 | kill -1 %% && echo i killed it || echo could not kill it 25 | -------------------------------------------------------------------------------- /tests/read2.sub: -------------------------------------------------------------------------------- 1 | a=4 2 | 3 | read -t 2 a < /dev/tty 4 | estat=$? 5 | if [ $estat -gt 128 ]; then 6 | echo timeout 1: ok 7 | else 8 | echo $estat 9 | fi 10 | 11 | echo $a 12 | 13 | sleep 5 | read -t 1 a 14 | estat=$? 15 | if [ $estat -gt 128 ]; then 16 | echo timeout 2: ok 17 | else 18 | echo $estat 19 | fi 20 | 21 | echo $a 22 | 23 | read -t -3 a < /dev/tty 24 | echo $? 25 | 26 | echo $a 27 | 28 | # the above should all time out 29 | echo abcde | { 30 | read -t 2 a 31 | echo $a 32 | } 33 | -------------------------------------------------------------------------------- /tests/dollar-at6.sub: -------------------------------------------------------------------------------- 1 | set -- ''; 2 | 3 | recho "${@}" x 4 | recho "${@:1}" x 5 | 6 | set -- "${@:1}" 7 | echo "$#" 8 | 9 | set -- '' '' 10 | 11 | recho "${@:1}" x 12 | recho "${@:1:1}" x 13 | 14 | typeset -a A # ksh93 needs this 15 | A=('' '') 16 | recho "${A[@]:0}" x 17 | 18 | recho "${A[@]:0:1}" x 19 | 20 | recho "${A[@]:1}" x 21 | 22 | set -- '' 23 | 24 | recho "${@/foo/bar}" 25 | recho "${@^^[abcde]}" 26 | 27 | A=( '' ) 28 | 29 | recho "${A[@]/foo/bar}" 30 | recho "${A[@],,[abcde]}" 31 | -------------------------------------------------------------------------------- /tests/jobs3.sub: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | NJOB=8 3 | i=0 4 | 5 | while [ $i -lt $NJOB ] 6 | do 7 | /bin/sh -c "sleep 4; exit 0" & 8 | rv=$? 9 | pid=$! 10 | eval bg_pid_$i=$pid 11 | # echo $$: Job $i: pid is $pid rv=$rv 12 | i=$((i + 1)) 13 | done 14 | 15 | 16 | 17 | i=0 18 | while [ $i -lt $NJOB ] 19 | do 20 | eval wpid=\$bg_pid_$i 21 | echo Waiting for job $i #'('pid $wpid')' 22 | wait $wpid 23 | rv=$? 24 | echo job $i returns $rv 25 | i=$((i + 1)) 26 | done 27 | -------------------------------------------------------------------------------- /tests/trap5.sub: -------------------------------------------------------------------------------- 1 | # make sure process substitution runs the exit trap 2 | [[ -n $(< <(trap "cat /dev/fd/0" EXIT)) ]] <</dev/null 2>&1 ); echo $? 7 | ! echo hello | grep h >/dev/null 2>&1 ; echo $? 8 | 9 | ! true ; echo $? 10 | ! false; echo $? 11 | 12 | ! (false) ; echo $? 13 | ! (true); echo $? 14 | 15 | ! true | false ; echo $? 16 | ! false | true ; echo $? 17 | 18 | ! (true | false) ; echo $? 19 | ! (false | true) ; echo $? 20 | -------------------------------------------------------------------------------- /MANIFEST.doc: -------------------------------------------------------------------------------- 1 | # 2 | # Master Manifest file for documentation-only distribution 3 | # 4 | doc d 5 | MANIFEST.doc f 6 | doc/article.ps f 7 | doc/rose94.ps f 8 | doc/bash.ps f 9 | doc/bashbug.ps f 10 | doc/builtins.ps f 11 | doc/rbash.ps f 12 | doc/bashref.ps f 13 | doc/bashref.dvi f 14 | doc/bash.0 f 15 | doc/bashbug.0 f 16 | doc/builtins.0 f 17 | doc/rbash.0 f 18 | doc/article.txt f 19 | doc/bash.html f 20 | doc/bashref.html f 21 | doc/article.pdf f 22 | doc/bash.pdf f 23 | doc/bashref.pdf f 24 | doc/rose94.pdf f 25 | -------------------------------------------------------------------------------- /tests/run-dbg-support2: -------------------------------------------------------------------------------- 1 | #!../bash 2 | #$Id: run-dbg-support2,v 1.3 2002/11/14 06:08:16 rockyb Exp $ 3 | 4 | TEST_NAME='dbg-support2' 5 | TEST_FILE="/tmp/${TEST_NAME}.check" 6 | ${THIS_SH} ./${TEST_NAME}.tests > $TEST_FILE 2>&1 < /dev/null 7 | set -f 8 | diff $TEST_FILE ${TEST_NAME}.right && rm -f $TEST_FILE 9 | 10 | # Return code tells testing mechanism whether passed or not. 11 | exit $? 12 | 13 | #;;; Local Variables: *** 14 | #;;; mode:shell-script *** 15 | #;;; eval: (sh-set-shell "bash") *** 16 | #;;; End: *** 17 | -------------------------------------------------------------------------------- /tests/comsub-posix2.sub: -------------------------------------------------------------------------------- 1 | # problem with bash-4.x versions before bash-4.2. required posix interp 2 | swap32_posix() 3 | { 4 | local funcname=swap32_posix 5 | local arg 6 | for arg in "$@"; do 7 | echo $(( 8 | ($arg & 4278190080) >> 24 | 9 | ($arg & 16711680) >> 8 | 10 | ($arg & 65280) << 8 | 11 | ($arg & 255) << 24 12 | )) 13 | done 14 | } 15 | 16 | type swap32_posix 17 | -------------------------------------------------------------------------------- /tests/exp1.sub: -------------------------------------------------------------------------------- 1 | # Test the substitution quoting characters (CTLESC and CTLNUL) in different 2 | # combinations 3 | 4 | recho `echo ''` 5 | recho `echo ""` 6 | recho `echo ` 7 | 8 | # Test the unquoted special quoting characters 9 | recho  10 | recho "" 11 | recho '' 12 | 13 | # This should give argv[1] = ^A argv[2] = ^? 14 | FOO=`echo ' ' | tr ' ' '\012'` 15 | recho $FOO 16 | 17 | # Test patterns that come up when the shell quotes funny character 18 | # combinations 19 | recho '' 20 | recho '' 21 | recho '' 22 | -------------------------------------------------------------------------------- /tests/varenv3.sub: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | oifs=$IFS 4 | 5 | inner () { 6 | #recho inner: "$IFS" >&2 7 | echo a/b/c/d 8 | exit 0 9 | } 10 | 11 | outer() { 12 | #recho outer: "$IFS" >&2 13 | for i in 1; do 14 | IFS=/ read m v k a < <(IFS=$oifs inner) 15 | 16 | echo $m:$v:$k:$a 17 | done 18 | } 19 | 20 | outer 21 | unset m k v a b c d 22 | 23 | for j in 1; do 24 | IFS=: read a b c d 25 | done < <(outer) 26 | 27 | echo $a-$b-$c-$d 28 | unset m k v a b c d 29 | 30 | IFS=: read a b c d < <(outer) 31 | 32 | echo $a:$b:$c:$d 33 | -------------------------------------------------------------------------------- /po/remove-potcdate.sin: -------------------------------------------------------------------------------- 1 | # Sed script that remove the POT-Creation-Date line in the header entry 2 | # from a POT file. 3 | # 4 | # The distinction between the first and the following occurrences of the 5 | # pattern is achieved by looking at the hold space. 6 | /^"POT-Creation-Date: .*"$/{ 7 | x 8 | # Test if the hold space is empty. 9 | s/P/P/ 10 | ta 11 | # Yes it was empty. First occurrence. Remove the line. 12 | g 13 | d 14 | bb 15 | :a 16 | # The hold space was nonempty. Following occurrences. Do nothing. 17 | x 18 | :b 19 | } 20 | -------------------------------------------------------------------------------- /tests/varenv1.sub: -------------------------------------------------------------------------------- 1 | # test out the export behavior of variable assignments preceding `eval', `.' 2 | # and shell functions 3 | 4 | func() 5 | { 6 | printenv var 7 | } 8 | 9 | export var=10 10 | echo expect 20 11 | var=20 eval printenv var 12 | 13 | : ${TMPDIR:=/tmp} 14 | TMPFILE=$TMPDIR/evalsub.$$ 15 | 16 | rm -f $TMPFILE 17 | echo 'printenv var' > $TMPFILE 18 | 19 | echo expect 30 20 | var=30 . $TMPFILE 21 | 22 | rm -f $TMPFILE 23 | 24 | echo expect 40 25 | var=40 func 26 | 27 | echo expect 50 28 | var=50 command printenv var 29 | -------------------------------------------------------------------------------- /tests/assoc5.sub: -------------------------------------------------------------------------------- 1 | declare -A myarray 2 | 3 | # this needs fixes to skipsubscript 4 | myarray["a]a"]="abc" 5 | 6 | echo ${myarray["a]a"]} 7 | 8 | myarray[$(echo ])]=def 9 | 10 | echo ${myarray[']']} 11 | echo ${myarray[\]]} 12 | 13 | declare myarray["foo[bar"]=bleh 14 | myarray["foo"]=bleh 15 | 16 | echo "${myarray[@]}" 17 | 18 | bar='a]=test1;#a' 19 | myarray[$bar]=123 20 | 21 | set | grep ^myarray= 22 | echo ${myarray[a]} 23 | 24 | echo "${myarray['a]=test1;#a']}" 25 | myarray['a]=test2;#a']="def" 26 | 27 | set | grep ^myarray= 28 | -------------------------------------------------------------------------------- /tests/intl3.sub: -------------------------------------------------------------------------------- 1 | . ./test-glue-functions 2 | 3 | # more tests to make sure that IFS splits on characters, not bytes 4 | export LANG=en_US.UTF-8 5 | 6 | euro=$'\342\202\254' 7 | o342=$'\342' 8 | o202=$'\202' 9 | o254=$'\254' 10 | 11 | IFS=$o254 12 | t=+$euro+ 13 | set -- $t 14 | 15 | echo "$#" 16 | 17 | # but matching still occurs on bytes if we don't have a valid multibyte char 18 | case $euro in 19 | *$o202*) echo bytematch ;; 20 | *) echo mbchar match ;; 21 | esac 22 | 23 | echo "${euro##*$o202}" | od -b | _intl_normalize_spaces 24 | -------------------------------------------------------------------------------- /tests/array12.sub: -------------------------------------------------------------------------------- 1 | # problems with fix for posix interp 217 introduced in bash-4.2 2 | 3 | declare -ax array 4 | array[$(( $( echo -n 1001 ) - 1001 ))]=1 5 | 6 | echo ${array[0]} 7 | echo ${array[@]} 8 | 9 | unset 'array[0]' 10 | array[$( echo -n 1001 ) - 1001 ]=1 11 | echo ${array[0]} 12 | 13 | unset 'array[0]' 14 | array[$(( 1001 - $( echo -n 1001 ) ))]=1 15 | echo ${array[0]} 16 | array[$(( 1001 - $( echo -n 1001 ) ))]=1 17 | echo ${array[0]} 18 | 19 | unset 'array[0]' 20 | array[1001 - $( echo -n 1001 )]=1 21 | echo ${array[0]} 22 | -------------------------------------------------------------------------------- /tests/array5.sub: -------------------------------------------------------------------------------- 1 | 2 | : ${TMPDIR:=/tmp} 3 | 4 | mkdir $TMPDIR/bash-test-$$ 5 | cd $TMPDIR/bash-test-$$ 6 | 7 | trap "cd / ; rm -rf $TMPDIR/bash-test-$$" 0 1 2 3 6 15 8 | 9 | touch '[3]=abcde' 10 | 11 | touch r s t u v 12 | 13 | declare -a x=(*) 14 | 15 | echo ${x[3]} 16 | echo ${x[@]} 17 | 18 | unset x 19 | x=(a b c d e) 20 | 21 | echo ${x[*]: -1} 22 | 23 | unset x[4] 24 | unset x[2] 25 | 26 | x[9]='9' 27 | 28 | echo ${x[*]: -1} 29 | 30 | TOOLKIT=(1 2 3 4 5 6 7 8 9 10) 31 | ARRAY="1" 32 | echo ${TOOLKIT["$ARRAY"]} 33 | 34 | exit 0 35 | -------------------------------------------------------------------------------- /tests/histexp3.sub: -------------------------------------------------------------------------------- 1 | HISTFILE=${TMPDIR}/bashhist-$$ 2 | 3 | set -o history 4 | set -o histexpand 5 | 6 | echo a 7 | echo $(echo !!) 8 | 9 | echo a 10 | echo !! $(echo !!) 11 | 12 | echo b 13 | echo '!!' '$(echo !!)' 14 | 15 | echo c 16 | echo "!!" "$(echo !!)" 17 | 18 | echo d 19 | echo "!!" $(echo "!!") 20 | 21 | echo e 22 | echo '!!' $(echo '!!') 23 | 24 | echo f 25 | echo '!!' 26 | echo f 27 | eval echo '!!' 28 | 29 | echo g 30 | echo "!!" 31 | echo g 32 | eval echo "!!" 33 | 34 | set +o history 35 | rm -f $HISTFILE # just in case 36 | -------------------------------------------------------------------------------- /tests/type4.sub: -------------------------------------------------------------------------------- 1 | bb() 2 | { 3 | ( 4 | cat << EOF 5 | foo 6 | bar 7 | EOF 8 | ) 9 | echo after subshell 10 | } 11 | 12 | type bb 13 | 14 | 15 | mkcoprocs() 16 | { 17 | coproc a { cat <&2 ; } 5 | 6 | : ${TMPDIR:=/tmp} 7 | 8 | cd $TMPDIR || { echo "cannot cd to $TMPDIR" >&2 ; exit 2; } 9 | 10 | mkdir testa testb 11 | 12 | echo 'echo "testa"' > testa/foo 13 | echo 'echo "testb"' > testb/foo 14 | 15 | chmod 655 testa/foo 16 | chmod 755 testb/foo 17 | 18 | PATH=$TMPDIR/testa:$TMPDIR/testb $THIS_SH -c foo 19 | 20 | rm -rf testa testb 21 | -------------------------------------------------------------------------------- /examples/startup-files/README: -------------------------------------------------------------------------------- 1 | Some sample startup files. The ones starting with capital letters 2 | are originally from Brian Fox. The ones starting with lowercase 3 | letters are from Chet Ramey. 4 | 5 | They will require changes for your environment. 6 | 7 | Bash_aliases Some useful aliases (Fox). 8 | Bash_profile Sample startup file for bash login shells (Fox). 9 | bash-profile Sample startup file for bash login shells (Ramey). 10 | bashrc Sample Bourne Again SHell init file (Ramey). 11 | Bashrc.bfox Sample Bourne Again SHell init file (Fox). 12 | README README 13 | -------------------------------------------------------------------------------- /tests/new-exp6.sub: -------------------------------------------------------------------------------- 1 | # quoted null problems in versions of bash prior to 3.2 2 | 3 | str='12' 4 | snul=$'\177' 5 | 6 | recho "${str:2}" 7 | recho "+${str:2}" 8 | recho "+${snul:0:1}" 9 | recho "+""${str:2}" 10 | 11 | recho "${str/?/$snul}" 12 | recho ${str/?/$snul} 13 | 14 | recho "${snul/x/y}" 15 | recho ${snul/x/y} 16 | 17 | recho "${snul/$snul/}" 18 | recho "${str/$str/}" 19 | 20 | recho "${snul##$snul}" 21 | recho "${str##$str}" 22 | recho "${str##$nul}" 23 | 24 | A="" 25 | B="${A:0}" 26 | 27 | recho "$B" 28 | recho "${A:0}" 29 | recho "/tmp/test/TEST${A:0}" 30 | -------------------------------------------------------------------------------- /tests/read5.sub: -------------------------------------------------------------------------------- 1 | IFS=: read x y z << EOF 2 | ::: 3 | EOF 4 | recho $x 5 | recho "$x" 6 | recho $y 7 | recho "$y" 8 | recho $z 9 | recho "$z" 10 | 11 | if [ -z "$x" ]; then 12 | echo FOO 13 | else 14 | echo BAR 15 | fi 16 | 17 | IFS=: read -a A << EOF 18 | ::: 19 | EOF 20 | 21 | recho ${A[0]} 22 | recho "${A[0]}" 23 | 24 | recho ${#A[@]} 25 | 26 | recho "${A[@]}" 27 | 28 | if [ -z "${A[0]}" ]; then 29 | echo FOO 30 | else 31 | echo BAR 32 | fi 33 | 34 | echo -n ${A[0]} | cat -vet 35 | echo -n ${A[0]} | wc | ( IFS=$' \t\n' ; while read line; do echo $line; done; ) 36 | -------------------------------------------------------------------------------- /tests/varenv2.sub: -------------------------------------------------------------------------------- 1 | fff() 2 | { 3 | typeset i=0 x=10 4 | echo "|$i|$x|" 5 | export x 6 | printenv x 7 | } 8 | 9 | fff2() 10 | { 11 | echo "|$x|" 12 | export x 13 | printenv x 14 | } 15 | 16 | fff3() 17 | { 18 | typeset i=0 x="${x-10}" 19 | echo "|$i|$x|" 20 | } 21 | 22 | fff4() 23 | { 24 | typeset i=0 x 25 | x="${x-10}" 26 | echo "|$i|$x|" 27 | } 28 | 29 | fff5() 30 | { 31 | z=y typeset z 32 | echo "|$z|" 33 | } 34 | 35 | fff 36 | x=10 fff 37 | x=1 fff 38 | x=4 fff2 39 | x=11 fff3 40 | echo after fff3: x=$x 41 | x=12 fff4 42 | 43 | fff5 44 | z=42 fff5 45 | -------------------------------------------------------------------------------- /tests/dbg-support2.tests: -------------------------------------------------------------------------------- 1 | #!../bash 2 | # 3 | # Test correct trap return codes = 2 means skip execution. 4 | shopt -s extdebug 5 | print_trap() { 6 | echo "lineno: $1 ($LINENO) ${FUNCNAME[1]}" 7 | if [[ $debug_exit == 2 ]] ; then 8 | debug_exit=0 9 | return 2 10 | fi 11 | return 0 12 | } 13 | 14 | debug_exit=0 15 | trap 'print_trap $LINENO' DEBUG 16 | 17 | x=1 18 | echo "x is $x" 19 | debug_exit=2 20 | x=2 21 | echo "x is $x" 22 | 23 | #;;; Local Variables: *** 24 | #;;; mode:shell-script *** 25 | #;;; eval: (sh-set-shell "bash") *** 26 | #;;; End: *** 27 | -------------------------------------------------------------------------------- /tests/set-e2.sub: -------------------------------------------------------------------------------- 1 | ${THIS_SH} -ce 'true || false ; echo "true || false no exit"' 2 | ${THIS_SH} -ce 'false || false ; echo "false || false no exit"' 3 | ${THIS_SH} -ce 'false || true ; echo "false || true no exit"' 4 | 5 | ${THIS_SH} -ce 'false && false ; echo "false && false no exit"' 6 | ${THIS_SH} -ce 'true && false ; echo "true && false no exit"' 7 | 8 | ${THIS_SH} -ce 'true && (exit 1) ; echo "true && (exit 1) no exit"' 9 | ${THIS_SH} -ce 'true && true|false ; echo "true && true|false no exit"' 10 | ${THIS_SH} -ce 'true && true|(false) ; echo "true && true|(false) no exit"' 11 | -------------------------------------------------------------------------------- /tests/array16.sub: -------------------------------------------------------------------------------- 1 | foo[0]=a 2 | foo[1]=b 3 | 4 | [[ -v foo[1] ]] && echo foo index 1: ok 5 | [[ -v foo[2] ]] || echo foo index 2: ok 6 | 7 | [[ -v foo ]] && echo foo: implicit reference to element 0: ok 8 | 9 | typeset -i foo 10 | 11 | [[ -v foo[1] ]] && echo foo: arithmetic evaluation: ok 12 | 13 | typeset -a bar 14 | bar[1]=set 15 | 16 | [[ -v bar ]] || echo bar: array with element zero unset: ok 17 | [[ -v bar[0] ]] || echo bar: element zero: ok 18 | 19 | typeset -a qux 20 | [[ -v qux ]] || echo qux: unset array: ok 21 | [[ -v qux[0] ]] || echo qux: unset array element 0: ok 22 | -------------------------------------------------------------------------------- /tests/extglob4.sub: -------------------------------------------------------------------------------- 1 | LANG=C 2 | LC_ALL=C 3 | 4 | : ${TMPDIR:=/tmp} 5 | GTDIR=$TMPDIR/extglob4-$$ 6 | 7 | shopt -s extglob 8 | [ -d "${GTDIR}" ] || mkdir "${GTDIR}" 9 | cd "${GTDIR}" || { 10 | echo "extglob4: cannot cd to ${GTDIR}" 11 | exit 2 12 | } 13 | 14 | touch a b c .x .y .z 15 | echo .!(|.) # correct 16 | echo * # correct 17 | 18 | echo @(*|.!(|.)) # wrong, adds . and .. 19 | echo @(*|@(f)) # ?? 20 | echo @(*|@(ff)) 21 | 22 | cd / 23 | rm -rf $GTDIR 24 | 25 | [[ a = a*?(/)b ]] && echo bad match 1 26 | -------------------------------------------------------------------------------- /tests/array4.sub: -------------------------------------------------------------------------------- 1 | # compound assignment parsing problems in bash-3.1-release 2 | func() 3 | { 4 | local -a x=() y=() 5 | } 6 | 7 | a=() b=() 8 | eval foo=() 9 | eval foo=() bar=() qux=( "bash" ) 10 | 11 | foo=( "bash" ) 12 | eval foo=( "bash" ) 13 | eval bar=( "bash" ) bax=( "bash" ) 14 | 15 | let a=(5 + 3) b=(4 + 7) 16 | echo $a $b 17 | 18 | typeset -i a b 19 | a=(5+3) b=(4+7) 20 | echo $a $b 21 | 22 | let a=(4*3)/2 23 | echo $a 24 | a=(4*3)/2 25 | echo $a 26 | 27 | LNAME=nordholz 28 | echo ${LNAME} 29 | echo ${#LNAME} 30 | 31 | echo ${#LNAME[$(( 0 ))]} 32 | echo ${#LNAME[$(( 0+0 ))]} 33 | -------------------------------------------------------------------------------- /tests/errors6.sub: -------------------------------------------------------------------------------- 1 | # problems with non-fatal expansion errors through bash-4.3 2 | : ${THIS_SH:=./bash} 3 | 4 | ${THIS_SH} -c 'echo ${x!y} second 5 | echo after 1: $?' 2>/dev/null 6 | 7 | ${THIS_SH} -c 'echo ${#+} second 8 | echo after 2: $?' 2>/dev/null 9 | 10 | ${THIS_SH} -c 'echo ${#foo%} second 11 | echo after 3: $?' 2>/dev/null 12 | 13 | ${THIS_SH} -c 'b[0]=4 ; echo ${b[ ]} 14 | echo array after 1: $?' 2>/dev/null 15 | ${THIS_SH} -c 'typeset -A v ; v["0"]=one ; echo ${v[ ]} 16 | echo array after 2: $?' 2>/dev/null 17 | 18 | echo ${-3} 19 | x=-3; echo ${!x} 20 | echo after indir: $? 21 | -------------------------------------------------------------------------------- /tests/func4.sub: -------------------------------------------------------------------------------- 1 | # test FUNCNEST functionality -- bash-4.2 2 | FUNCNEST=100 3 | 4 | foo() 5 | { 6 | (( f++ )) 7 | if (( f > 200 )); then 8 | return 7 9 | fi 10 | foo 11 | } 12 | 13 | f=0 14 | foo 15 | echo $? 16 | echo after: f = $f 17 | 18 | f=0 19 | foo 20 | echo $? 21 | echo after: f = $f 22 | 23 | f=0 24 | FUNCNEST=0 25 | foo 26 | echo $? 27 | echo after FUNCNEST reset: f = $f 28 | 29 | f=0 30 | unset FUNCNEST 31 | foo 32 | echo $? 33 | echo after FUNCNEST unset: f = $f 34 | 35 | FUNCNEST=20 36 | f=$(( FUNCNEST - 2 )) 37 | foo 38 | echo $? 39 | echo after FUNCNEST assign: f = $f 40 | -------------------------------------------------------------------------------- /tests/posixpipe.tests: -------------------------------------------------------------------------------- 1 | # Test timed and negated pipelines in bash-4.2 and later 2 | export TIMEFORMAT=$'real %2R\nuser %2U\nsys %2S' 3 | 4 | ! 5 | echo $? 6 | 7 | ! ! 8 | echo $? 9 | 10 | time ! echo a 11 | echo $? 12 | 13 | ! time echo a 14 | echo $? 15 | 16 | tfunc() 17 | { 18 | time 19 | } 20 | 21 | type tfunc 22 | 23 | ! true 24 | echo $? 25 | ! ! true 26 | echo $? 27 | ! ! ! true 28 | echo $? 29 | 30 | time time echo a 31 | echo $? 32 | 33 | time time -p echo a 34 | echo $? 35 | time -p time echo a 36 | echo $? 37 | 38 | ! 39 | echo $? 40 | ! ! 41 | echo $? 42 | 43 | time -p -- echo a 44 | -------------------------------------------------------------------------------- /CWRU/PLATFORMS: -------------------------------------------------------------------------------- 1 | The version of bash in this directory has been compiled on the 2 | following systems: 3 | 4 | By chet: 5 | 6 | SunOS 4.1.4 7 | SunOS 5.5 8 | BSDI BSD/OS 2.1 9 | FreeBSD 2.2 10 | NetBSD 1.2 11 | AIX 4.2 12 | AIX 4.1.4 13 | HP/UX 9.05, 10.01, 10.10, 10.20 14 | Linux 2.0.29 (libc 5.3.12) 15 | Linux 2.0.4 (libc 5.3.12) 16 | 17 | By other testers: 18 | 19 | SCO ODT 2.0 20 | SCO 3.2v5.0, 3.2v4.2 21 | SunOS 5.3 22 | SunOS 5.5 23 | BSD/OS 2.1 24 | FreeBSD 2.2 25 | SunOS 4.1.3 26 | Irix 5.3 27 | Irix 6.2 28 | Linux 2.0 (unknown distribution) 29 | Digital OSF/1 3.2 30 | GNU Hurd 0.1 31 | SVR4.2 32 | -------------------------------------------------------------------------------- /tests/exportfunc.right: -------------------------------------------------------------------------------- 1 | exportfunc ok 1 2 | exportfunc ok 2 3 | ./exportfunc.tests: line 24: cve7169-bad: No such file or directory 4 | ./exportfunc.tests: eval: line 31: syntax error: unexpected end of file 5 | ./exportfunc.tests: line 30: cve7169-bad2: No such file or directory 6 | ./exportfunc1.sub: line 1: maximum here-document count exceeded 7 | ./exportfunc.tests: line 51: HELLO_WORLD: No such file or directory 8 | eval ok 9 | ./exportfunc3.sub: line 10: export: foo=bar: cannot export 10 | status: 1 11 | equals-1 12 | bad echo 13 | ./exportfunc3.sub: line 23: export: /bin/echo: cannot export 14 | bar 15 | -------------------------------------------------------------------------------- /tests/comsub3.sub: -------------------------------------------------------------------------------- 1 | x=$( 2 | case 1 in 3 | 1) echo 1 4 | esac 5 | case 2 in 6 | 2) echo 2 7 | esac 8 | ) 9 | echo "$x" 10 | 11 | x=$(case 1 in 1) echo 3;; esac; case 2 in 2) echo 4;; esac;) 12 | echo "$x" 13 | 14 | x=$(case 1 in 1) echo 5;; esac; case 2 in 2) echo 6;; esac) 15 | echo "$x" 16 | 17 | x=$(case 1 in 1) echo 5;; esac; case 2 in 2) echo 6;; esac; for f in a b c; do echo "$f" ; done) 18 | echo "$x" 19 | 20 | x=$( 21 | for f in a b c; do 22 | echo $f 23 | done 24 | case 1 in 25 | 1) echo 1 26 | esac 27 | case 2 in 28 | 2) echo 2 29 | esac 30 | ) 31 | echo "$x" 32 | -------------------------------------------------------------------------------- /tests/exp8.sub: -------------------------------------------------------------------------------- 1 | var=$'x\001y\177z' 2 | 3 | recho "$var" 4 | recho $var 5 | 6 | declare -p var 7 | recho $(declare -p var) 8 | 9 | declare -p var | sed -n l 10 | 11 | recho ${var@Q} 12 | recho ${var@P} 13 | echo ${var@A} 14 | 15 | unset array 16 | array=( [$'x\001y\177z']=foo ) # should be error 17 | echo ${array[@]@A} 18 | 19 | unset array 20 | declare -a array=([0]=$'x\001y\177z') 21 | declare -p array 22 | 23 | unset array 24 | array=( "$var" ) 25 | recho ${array[@]} 26 | echo ${array[@]@A} 27 | 28 | unset array 29 | declare -A array 30 | array=( [$'x\001y\177z']=$'a\242b\002c' ) 31 | echo ${array[@]@A} 32 | -------------------------------------------------------------------------------- /tests/getopts2.sub: -------------------------------------------------------------------------------- 1 | aflag= 2 | bflag= 3 | 4 | while getopts ab:c:de name "$@" 5 | do 6 | case $name in 7 | a) aflag=1 ;; 8 | b) bflag=1 9 | bval=$OPTARG;; 10 | c) cflag=1 11 | cval=$OPTARG ;; 12 | d) dflag=1 ;; 13 | e) eflag=1;; 14 | ?) echo Usage: $0 [-a] [-b value] [-c value] -[de] args 15 | exit 2;; 16 | esac 17 | 18 | done 19 | 20 | [ ! -z "$aflag" ] && echo -a specified 21 | [ ! -z "$bflag" ] && echo -b $bval specified 22 | [ ! -z "$cflag" ] && echo -c $cval specified 23 | [ ! -z "$dflag" ] && echo -d specified 24 | [ ! -z "$eflag" ] && { echo -n - ; echo e specified; } 25 | 26 | exit 0 27 | -------------------------------------------------------------------------------- /tests/getopts3.sub: -------------------------------------------------------------------------------- 1 | aflag= 2 | bflag= 3 | 4 | while getopts ab: name -a -b 1 -a -a -a -b 5 -b 3 -a one two three four five 5 | do 6 | case $name in 7 | a) aflag=1 ;; 8 | b) bflag=1 9 | bval=$OPTARG;; 10 | ?) echo Usage: $0 [-a] [-b value] args 11 | exit 2;; 12 | esac 13 | 14 | done 15 | 16 | if [ ! -z "$aflag" ] ; then echo -a specified ; fi 17 | if [ ! -z "$bflag" ] ; then echo -b $bval specified ; fi 18 | 19 | set -- -a -b 1 -a -a -a -b 5 -b 3 -a one two three four five 20 | if [ "$OPTIND" -gt 1 ] 21 | then 22 | shift $(( $OPTIND - 1 )) 23 | fi 24 | 25 | echo remaining args: "$*" 26 | 27 | exit 0 28 | -------------------------------------------------------------------------------- /tests/array18.sub: -------------------------------------------------------------------------------- 1 | # arrays referenced using @ subscript and positional parameters should behave 2 | # the same way 3 | 4 | foo=(0 0 0); [[ -z ${foo[@]#0} ]]; echo $? 5 | 6 | recho "${foo[@]#0}" 7 | bar=${foo[@]#0} 8 | recho bar 9 | recho $bar 10 | recho -$bar- 11 | recho "$bar" 12 | 13 | qux="${foo[@]#0}" 14 | recho qux 15 | recho $qux 16 | recho -$qux- 17 | recho "$qux" 18 | 19 | unset foo qux bar 20 | 21 | set -- 0 0 0 22 | 23 | recho "${@#0}" 24 | bar=${@#0} 25 | recho bar 26 | recho $bar 27 | recho -$bar- 28 | recho "$bar" 29 | 30 | qux="${@#0}" 31 | recho qux 32 | recho $qux 33 | recho -$qux- 34 | recho "$qux" 35 | -------------------------------------------------------------------------------- /tests/herestr.right: -------------------------------------------------------------------------------- 1 | abcde 2 | yo 3 | hot damn 4 | what a fabulous window treatment 5 | double"quote 6 | onetwothree 7 | first second third 8 | f1 () 9 | { 10 | cat <<< "abcde"; 11 | cat <<< "yo"; 12 | cat <<< "$a $b"; 13 | cat <<< 'what a fabulous window treatment'; 14 | cat <<< 'double"quote' 15 | } 16 | f2 () 17 | { 18 | cat <<< onetwothree 19 | } 20 | f3 () 21 | { 22 | cat <<< "$@" 23 | } 24 | echo $(echo hi) 25 | echo ho 26 | echo off to work we go 27 | declare -a uu=([0]="" [1]="kghfjk" [2]="jkfzuk" [3]=$'i\n') 28 | foo bar 29 | foo bar 30 | qux:::::bax 31 | qux:::::bax 32 | -------------------------------------------------------------------------------- /tests/herestr.tests: -------------------------------------------------------------------------------- 1 | a=hot 2 | b=damn 3 | f1() 4 | { 5 | cat <<< "abcde" 6 | 7 | cat <<< "yo" 8 | 9 | cat <<< "$a $b" 10 | 11 | cat <<< 'what a fabulous window treatment' 12 | 13 | cat <<< 'double"quote' 14 | } 15 | 16 | f2() 17 | { 18 | cat <<< onetwothree 19 | } 20 | 21 | f3() 22 | { 23 | cat <<< "$@" 24 | } 25 | 26 | f1 27 | f2 28 | f3 first second third 29 | 30 | typeset -f 31 | 32 | cat <<< 'echo $(echo hi)' 33 | 34 | cat <<< "echo ho" 35 | 36 | cat <<< "echo $(echo off to work we go)" 37 | 38 | IFS="/" read -r -d $'\000' -a uu <<< /kghfjk/jkfzuk/i 39 | declare -p uu 40 | 41 | ${THIS_SH} ./herestr1.sub 42 | -------------------------------------------------------------------------------- /tests/arith1.sub: -------------------------------------------------------------------------------- 1 | # test of redone post-increment and post-decrement code 2 | echo $(( 4-- )) 3 | echo $(( 4++ )) 4 | echo $(( 4 -- )) 5 | echo $(( 4 ++ )) 6 | 7 | (( array[0]++ )) 8 | echo ${array} 9 | 10 | (( array[0] ++ )) 11 | echo ${array} 12 | 13 | (( a++ )) 14 | echo $a 15 | (( a ++ )) 16 | echo $a 17 | 18 | echo $(( a ++ + 4 )) 19 | echo $a 20 | 21 | echo $(( a+++4 )) 22 | echo $a 23 | 24 | echo $(( a---4 )) 25 | echo $a 26 | 27 | echo $(( a -- + 4 )) 28 | echo $a 29 | 30 | echo $(( a -- - 4 )) 31 | echo $a 32 | 33 | (( ++ + 7 )) 34 | 35 | (( ++ )) 36 | echo $(( +++7 )) 37 | echo $(( ++ + 7 )) 38 | (( -- )) 39 | -------------------------------------------------------------------------------- /tests/appendop.right: -------------------------------------------------------------------------------- 1 | 14 2 | 1 2 3 4 5 6 3 | 1 2 3 4 51 6 4 | 145 5 | 14 6 | 7 7 | 42 8 | 1 2 3 4 12 9 | 18 10 | 1 2 3 4 18 11 | 1 2 7 4 5 12 | 1 2 7 13 5 9 13 | 14 14 | 9 15 | 4 16 | 9 17 | 16 18 | ./appendop.tests: line 84: x: readonly variable 19 | declare -A foo=([two]="baz" [three]="quux" [one]="bar" ) 20 | declare -A foo=([two]="baz" [0]="zero" [three]="quux" [one]="bar" ) 21 | declare -A foo=([two]="baz" [0]="zero" [three]="quux" [four]="four" [one]="bar" ) 22 | declare -ai iarr=([0]="3" [1]="2" [2]="3") 23 | declare -ai iarr=([0]="3" [1]="2" [2]="3" [3]="4" [4]="5" [5]="6") 24 | 25 25 25 | 7 7 26 | 14 27 | 145 28 | 145 145 29 | -------------------------------------------------------------------------------- /support/SYMLINKS: -------------------------------------------------------------------------------- 1 | # 2 | # symlink map for bash source tree 3 | # 4 | # link name link target 5 | # 6 | lib/readline/tilde.c ../tilde/tilde.c 7 | lib/readline/tilde.h ../tilde/tilde.h 8 | # 9 | lib/readline/ansi_stdlib.h ../../include/ansi_stdlib.h 10 | lib/readline/posixdir.h ../../include/posixdir.h 11 | lib/readline/posixjmp.h ../../include/posixjmp.h 12 | lib/readline/posixselect.h ../../include/posixselect.h 13 | lib/readline/posixstat.h ../../include/posixstat.h 14 | #lib/readline/rlstdc.h ../../include/stdc.h 15 | #lib/readline/xmalloc.c ../malloc/xmalloc.c 16 | # 17 | #lib/tilde/memalloc.h ../../include/memalloc.h 18 | # 19 | -------------------------------------------------------------------------------- /CWRU/README: -------------------------------------------------------------------------------- 1 | Contents of this directory: 2 | 3 | changelog - my change log since the last release 4 | 5 | POSIX.NOTES - list of what changes for `posix mode' 6 | 7 | README - this file 8 | 9 | misc - directory with some useful tools 10 | 11 | The following are distributed `as-is'. They will not apply without some 12 | modification. 13 | 14 | sh-redir-hack - diff to parse.y to get redirections before 15 | compound commands 16 | 17 | empty-for-wordlist - diff to parse.y to allow an empty wordlist after 18 | the `in' keyword in a `for' statement 19 | 20 | mh-folder-comp - diffs that reportedly add MH folder completion 21 | -------------------------------------------------------------------------------- /tests/redir9.sub: -------------------------------------------------------------------------------- 1 | : ${TMPDIR:=/tmp} 2 | 3 | func() 4 | { 5 | echo "to stdout" 6 | echo "to stderr" >&2 7 | } 8 | 9 | TMPFN=$TMPDIR/foo-$$ 10 | 11 | rm -f $TMPFN 12 | 13 | echo hey > $TMPFN 14 | func &>> $TMPFN 15 | 16 | cat $TMPFN 17 | 18 | echo 19 | func &> $TMPFN 20 | 21 | cat $TMPFN 22 | 23 | echo 24 | func >$TMPFN 25 | cat $TMPFN 26 | 27 | echo 28 | echo hey > $TMPFN 29 | func >> $TMPFN 30 | cat $TMPFN 31 | 32 | rm -f $TMPFN 33 | 34 | logfunc() 35 | { 36 | echo "$@" &>> $TMPDIR/log 37 | } 38 | 39 | type logfunc 40 | 41 | echo foo 2>&1 42 | 43 | bix() 44 | { 45 | echo foo |& cat 46 | } 47 | 48 | type bix 49 | 50 | bix 51 | -------------------------------------------------------------------------------- /tests/lastpipe2.sub: -------------------------------------------------------------------------------- 1 | shopt -s lastpipe 2 | echo -e 'A\nB' | while read letter; do 3 | echo -e '1\n2' | while read digit; do 4 | echo $letter$digit 5 | done 6 | done 7 | 8 | myPipefunc() 9 | { 10 | cat | tee $TMPDIR/outfile 11 | } 12 | echo HI | myPipefunc 13 | 14 | echo -e 'A\nB' | while read letter; do 15 | echo -e '1\n2' | while read digit; do 16 | echo $letter$digit | myPipefunc 17 | done 18 | done 19 | 20 | rm -f $TMPDIR/outfile 21 | 22 | unset -f myPipefunc 23 | myPipefunc() 24 | { 25 | cat | read var 26 | return 42 27 | } 28 | echo HI | myPipefunc 29 | 30 | echo $var -- $? -- ${PIPESTATUS[@]} 31 | -------------------------------------------------------------------------------- /tests/run-new-exp: -------------------------------------------------------------------------------- 1 | echo "warning: two of these tests will fail if your OS does not support" >&2 2 | echo "warning: named pipes or the /dev/fd filesystem. If the tests of the" >&2 3 | echo "warning: process substitution mechanism fail, please do not consider" >&2 4 | echo "warning: this a test failure" >&2 5 | echo "warning: if you have exported variables beginning with the string _Q," >&2 6 | echo "warning: diff output may be generated. If so, please do not consider" >&2 7 | echo "warning: this a test failure" >&2 8 | 9 | ${THIS_SH} ./new-exp.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT} 10 | diff ${BASH_TSTOUT} new-exp.right && rm -f ${BASH_TSTOUT} 11 | -------------------------------------------------------------------------------- /tests/new-exp9.sub: -------------------------------------------------------------------------------- 1 | indirarray() 2 | { 3 | local intermediary 4 | local sub 5 | 6 | intermediary="${1}[@]" 7 | local -a leftValue=("${!intermediary}") 8 | 9 | local -a leftSub 10 | eval leftSub=(\"\${!${1}[@]}\") 11 | 12 | echo "$1" Value = ${leftValue[@]} 13 | echo "$1" Sub = ${leftSub[@]} 14 | } 15 | 16 | a=(1 2 3 4 5) 17 | b=(a b c d e) 18 | 19 | c=([0]=10 [2]=20 [4]=40 [8]=80) 20 | 21 | indirarray a 22 | indirarray b 23 | indirarray c 24 | 25 | ref=a 26 | tmp="$ref[@]" 27 | printf "<%s> " "${!tmp}"; echo # Iterate whole array. 28 | 29 | ref=c 30 | tmp="$ref[@]" 31 | printf "<%s> " "${!tmp}"; echo # Iterate whole array. 32 | -------------------------------------------------------------------------------- /tests/array21.sub: -------------------------------------------------------------------------------- 1 | typeset -a a 2 | a=(1 2 3 4) 3 | 4 | typeset -A A 5 | A=([one]=1 [two]=2 [three]=3 [four]=4) 6 | 7 | unset 'a[0]' 8 | typeset -p a 9 | 10 | scalar=abcd 11 | echo ${scalar[0]} 12 | 13 | unset 'scalar[0]' 14 | echo ${scalar-unset} 15 | 16 | unset 'a[@]' 17 | typeset -p a 18 | 19 | unset 'A[@]' 20 | typeset -p A 21 | 22 | typeset -a a 23 | a=(1 2 3 4) 24 | typeset -A A 25 | A=([one]=1 [two]=2 [three]=3 [four]=4) 26 | 27 | # supported, recommended way to unset all array elements 28 | a=() 29 | typeset -p a 30 | A=() 31 | typeset -p A 32 | 33 | declare -a foo 34 | declare foo='(1 2 3)' 35 | declare foo[1]='(4 5 6)' 36 | 37 | declare -p foo 38 | -------------------------------------------------------------------------------- /tests/run-execscript: -------------------------------------------------------------------------------- 1 | echo "warning: the text of a system error message may vary between systems and" >&2 2 | echo "warning: produce diff output." >&2 3 | echo "warning: if the text of the error messages concerning \`notthere' or" >&2 4 | echo "warning: \`/tmp/bash-notthere' not being found or \`/' being a directory" >&2 5 | echo "warning: produce diff output, please do not consider this a test failure" >&2 6 | echo "warning: if diff output differing only in the location of the bash" >&2 7 | echo "warning: binary appears, please do not consider this a test failure" >&2 8 | ${THIS_SH} ./execscript > ${BASH_TSTOUT} 2>&1 9 | diff ${BASH_TSTOUT} exec.right && rm -f ${BASH_TSTOUT} 10 | -------------------------------------------------------------------------------- /examples/loadables/perl/iperl.c: -------------------------------------------------------------------------------- 1 | #include /* from the Perl distribution */ 2 | #include /* from the Perl distribution */ 3 | 4 | extern void xs_init _((void)); 5 | 6 | static PerlInterpreter *iperl; /*** The Perl interpreter ***/ 7 | 8 | int 9 | perl_main(int argc, char **argv, char **env) 10 | { 11 | int r; 12 | 13 | iperl = perl_alloc(); 14 | perl_construct(iperl); 15 | perl_parse(iperl, xs_init, argc, argv, (char **)NULL); 16 | r = perl_run(iperl); 17 | 18 | PerlIO_flush(PerlIO_stdout()); 19 | PerlIO_flush(PerlIO_stderr()); 20 | 21 | perl_destruct(iperl); 22 | perl_free(iperl); 23 | return (r); 24 | } 25 | -------------------------------------------------------------------------------- /examples/functions/dirname: -------------------------------------------------------------------------------- 1 | # Date: Fri, 11 Oct 91 11:22:36 edt 2 | # From: friedman@gnu.ai.mit.edu 3 | # To: bfox@gnu.ai.mit.edu 4 | 5 | # A replacement for dirname(1). This one appears less often on some 6 | # systems I use than basename(1), and I really depend on it for some 7 | # things. Usage: dirname [path] 8 | function dirname () 9 | { 10 | local dir="$1" 11 | local tdir="${dir%/}" 12 | 13 | # Strip trailing '/' characters from dir (unusual that this should 14 | # ever occur, but dirname(1) seems to deal with it.) 15 | while [ "${tdir}" != "${dir}" ]; do 16 | tdir="${dir}" 17 | dir="${tdir%/}" 18 | done 19 | 20 | echo "${dir%/*}" 21 | } 22 | -------------------------------------------------------------------------------- /tests/dbg-support3.sub: -------------------------------------------------------------------------------- 1 | shopt -s extdebug 2 | 3 | callstack(){ 4 | deep=${#BASH_ARGV[*]} 5 | echo "deep $deep" 6 | i=0 7 | for ff in ${BASH_ARGV[@]} 8 | do 9 | echo "$i $ff" 10 | i=$(($i+1)) 11 | done 12 | } 13 | 14 | f3() 15 | { 16 | echo $FUNCNAME: calling callstack 17 | callstack 18 | echo FUNCNAME stack: ${FUNCNAME[@]} 19 | caller 0 20 | echo $FUNCNAME: returning 21 | } 22 | 23 | f2() 24 | { 25 | echo $FUNCNAME: calling f3 26 | f3 3 z 27 | echo $FUNCNAME: return from f3 28 | } 29 | 30 | f1() 31 | { 32 | echo $FUNCNAME: calling f2 33 | f2 2 y 34 | echo $FUNCNAME: return from f2 35 | } 36 | 37 | echo main: calling f1 38 | f1 1 x 39 | echo main: f1 returns 40 | -------------------------------------------------------------------------------- /tests/getopts4.sub: -------------------------------------------------------------------------------- 1 | aflag= 2 | bflag= 3 | 4 | while getopts :ab: name "$@" 5 | do 6 | case $name in 7 | a) aflag=1 ;; 8 | b) bflag=1 9 | bval=$OPTARG;; 10 | :) echo $0: error: option \`$OPTARG\' requires an argument 11 | echo Usage: $0 [-a] [-b value] args 12 | exit 2;; 13 | ?) echo $0: error: illegal option character \`$OPTARG\' 14 | echo Usage: $0 [-a] [-b value] args 15 | exit 2;; 16 | esac 17 | 18 | done 19 | 20 | if [ ! -z "$aflag" ] ; then echo -a specified ; fi 21 | if [ ! -z "$bflag" ] ; then echo -b $bval specified ; fi 22 | 23 | if [ "$OPTIND" -gt 1 ] 24 | then 25 | shift $(( $OPTIND - 1 )) 26 | fi 27 | 28 | echo remaining args: "$*" 29 | 30 | exit 0 31 | -------------------------------------------------------------------------------- /tests/getopts7.sub: -------------------------------------------------------------------------------- 1 | aflag= 2 | bflag= 3 | 4 | while getopts :ab: opt-var "$@" 5 | do 6 | case $name in 7 | a) aflag=1 ;; 8 | b) bflag=1 9 | bval=$OPTARG;; 10 | :) echo $0: error: option \`$OPTARG\' requires an argument 11 | echo Usage: $0 [-a] [-b value] args 12 | exit 2;; 13 | ?) echo $0: error: illegal option character \`$OPTARG\' 14 | echo Usage: $0 [-a] [-b value] args 15 | exit 2;; 16 | esac 17 | 18 | done 19 | 20 | if [ ! -z "$aflag" ] ; then echo -a specified ; fi 21 | if [ ! -z "$bflag" ] ; then echo -b $bval specified ; fi 22 | 23 | if [ "$OPTIND" -gt 1 ] 24 | then 25 | shift $(( $OPTIND - 1 )) 26 | fi 27 | 28 | echo remaining args: "$*" 29 | 30 | exit 0 31 | -------------------------------------------------------------------------------- /tests/array11.sub: -------------------------------------------------------------------------------- 1 | # problems with associative array keys with ] and unbalanced [ ] 2 | # fixed after bash-4.2 3 | 4 | declare -A foo 5 | 6 | foo=(["version[agent]"]=version.agent) 7 | 8 | echo ${!foo[@]} 9 | echo ${foo[@]} 10 | 11 | unset foo 12 | declare -A foo 13 | foo["version[agent]"]=version.agent 14 | 15 | echo ${!foo[@]} 16 | echo ${foo[@]} 17 | 18 | declare foo["foo[bar]"]=bowl 19 | 20 | echo ${!foo[@]} 21 | echo ${foo[@]} 22 | 23 | declare -A array2["foo[bar]"]=bleh 24 | 25 | array2["foobar]"]=bleh 26 | array2["foo"]=bbb 27 | 28 | echo ${!array2[@]} 29 | echo ${array2[@]} 30 | 31 | declare -A foo 32 | foo=( ['ab]']=bar ) 33 | 34 | echo ${!foo[@]} 35 | echo ${foo[@]} 36 | -------------------------------------------------------------------------------- /tests/builtins4.sub: -------------------------------------------------------------------------------- 1 | declare -a c 2 | declare -p c 3 | 4 | declare -A d 5 | declare -p d 6 | unset c d 7 | 8 | declare -a c 9 | c=4 10 | declare -p c 11 | unset c 12 | 13 | declare -A c 14 | c=4 15 | declare -p c 16 | unset c 17 | 18 | declare -a c 19 | c=(1 2 3) 20 | declare -p c 21 | unset c 22 | 23 | declare -A c 24 | c=([one]=1 [two]=2 [three]=3) 25 | declare -p c 26 | unset c 27 | 28 | declare -a c 29 | read -a c < <(echo 1 2 3) 30 | declare -p c 31 | unset c 32 | 33 | declare -a c 34 | mapfile -t c < <(echo 1$'\n'2$'\n'3) 35 | declare -p c 36 | unset c 37 | 38 | unset foo 39 | declare -A foo 40 | echo ${foo-unset} 41 | 42 | unset foo 43 | declare -a foo 44 | echo ${foo-unset} 45 | -------------------------------------------------------------------------------- /tests/dstack2.tests: -------------------------------------------------------------------------------- 1 | cd / 2 | 3 | echo expect '~1' 4 | echo ~1 5 | 6 | pushd /usr 7 | pushd /tmp 8 | dirs 9 | 10 | echo these lines should be the same 11 | dirs +0 12 | echo ~0 ${DIRSTACK[0]} 13 | echo these lines should be the same 14 | dirs +1 15 | echo ~1 ${DIRSTACK[1]} 16 | echo these lines should be the same 17 | dirs +2 18 | echo ~2 ${DIRSTACK[2]} 19 | 20 | NDIRS=$(( ${#DIRSTACK[@]} - 1 )) 21 | 22 | echo these lines should be the same 23 | dirs -2 24 | echo ~-2 ${DIRSTACK[NDIRS-2]} 25 | 26 | echo these lines should be the same 27 | dirs -1 28 | echo ~-1 ${DIRSTACK[NDIRS-1]} 29 | dirs -v -1 30 | 31 | echo these lines should be the same 32 | dirs -0 33 | echo ~-0 ${DIRSTACK[NDIRS]} 34 | -------------------------------------------------------------------------------- /tests/arith2.sub: -------------------------------------------------------------------------------- 1 | echo $(( --7 )) 2 | echo $(( ++7 )) 3 | echo $(( -- 7 )) 4 | echo $(( ++ 7 )) 5 | 6 | ((++array[0] )) 7 | echo $array 8 | (( ++ array[0] )) 9 | echo $array 10 | 11 | (( ++a )) 12 | echo $a 13 | (( ++ a )) 14 | echo $a 15 | 16 | (( --a )) 17 | echo $a 18 | (( -- a )) 19 | echo $a 20 | 21 | echo $(( 4 + ++a )) 22 | echo $a 23 | 24 | echo $(( 4+++a )) 25 | echo $a 26 | 27 | echo $(( 4---a )) 28 | echo $a 29 | 30 | echo $(( 4 - -- a )) 31 | echo $a 32 | 33 | (( -- )) 34 | echo $(( ---7 )) 35 | echo $(( -- - 7 )) 36 | 37 | (( ++ )) 38 | echo $(( ++7 )) 39 | echo $(( ++ + 7 )) 40 | 41 | echo $(( ++-7 )) 42 | echo $(( ++ - 7 )) 43 | 44 | echo $(( +--7 )) 45 | echo $(( -- + 7 )) 46 | -------------------------------------------------------------------------------- /tests/nquote2.sub: -------------------------------------------------------------------------------- 1 | t() { 2 | printf '%s | %s\n' "$1" "$2" 3 | } 4 | v="'" # v <- ' 5 | 6 | #-- 7 | t "${v/$'\''/$'\''}" "'" 8 | t ${v/$'\''/$'\''} "'" 9 | t "${v/$'\''/x}" "x" 10 | t ${v/$'\''/x} "x" 11 | t "${v/x/$'\''}" "'" 12 | t ${v/x/$'\''} "'" 13 | t "${v/x/$'\x5c\''}" "'" 14 | t ${v/x/$'\x5c\''} "'" 15 | t "${v/\'/\'}" "'" 16 | t ${v/\'/\'} "'" 17 | t ${v/\'/x} "x" 18 | 19 | echo "'" 20 | echo "$'\''" 21 | 22 | echo $'\'' 23 | 24 | echo $'\'abcd\'' 25 | echo "$'\'abcd\''" 26 | 27 | v=1 28 | echo ${v/1/\'} 29 | echo ${v/\'/2} 30 | -------------------------------------------------------------------------------- /tests/rsh.tests: -------------------------------------------------------------------------------- 1 | # test restricted shell mode -- these should all be errors 2 | # 3 | # things not tested for: 4 | # adding builtins dynamically with enable -f 5 | # importing function definitions from environment 6 | 7 | set -r 8 | 9 | cd / 10 | PATH=$PATH:/usr/local/bin 11 | SHELL=/bin/sh 12 | /bin/sh -c 'echo /bin/sh executed' 13 | 14 | . ./source.sub3 15 | 16 | rm -f /tmp/restricted 17 | echo abc > /tmp/restricted 18 | if [ -f /tmp/restricted ]; then 19 | echo oops 1 -- output 20 | fi 21 | echo abc >> /tmp/restricted 22 | if [ -f /tmp/restricted ]; then 23 | echo oops 2 -- append 24 | fi 25 | 26 | command -p date 27 | 28 | set +r 29 | set +o restricted 30 | 31 | exec /bin/date 32 | 33 | echo $0: after exec 34 | -------------------------------------------------------------------------------- /tests/vredir.tests: -------------------------------------------------------------------------------- 1 | : ${TMPDIR:=/var/tmp} 2 | TMPFILE=$TMPDIR/foo 3 | 4 | bar() 5 | { 6 | exec {v}>$TMPFILE 7 | echo $v 8 | } 9 | 10 | bar 11 | 12 | echo foo 1 >&$v 13 | echo foo 2 >&$v 14 | echo foo 3 >&$v 15 | 16 | cat $TMPFILE 17 | rm -f $TMPFILE 18 | 19 | type bar 20 | exec {v}>&- 21 | 22 | readonly v=42 23 | bar 24 | 25 | echo foo 1 >&$v 26 | echo foo 2 >&$v 27 | echo foo 3 >&$v 28 | 29 | cat $TMPFILE 30 | rm -f $TMPFILE 31 | 32 | type bar 33 | 34 | ${THIS_SH} ./vredir1.sub 35 | 36 | ${THIS_SH} ./vredir2.sub 37 | 38 | ${THIS_SH} ./vredir3.sub 39 | 40 | ${THIS_SH} ./vredir4.sub 41 | 42 | ${THIS_SH} ./vredir5.sub 43 | 44 | ${THIS_SH} ./vredir6.sub 45 | 46 | ${THIS_SH} ./vredir7.sub 47 | 48 | exit 0 49 | -------------------------------------------------------------------------------- /tests/vredir2.sub: -------------------------------------------------------------------------------- 1 | : ${TMPDIR:=/var/tmp} 2 | SHELLSFILE=$TMPDIR/shells-$$ 3 | 4 | cat > $TMPDIR/shells-$$ <&- 16 | } 17 | 18 | iclosev() 19 | { 20 | exec {v}<&- 21 | } 22 | 23 | exec {v}>&1 24 | echo $v 25 | 26 | echo foo 1 >&$v 27 | echo foo 2 >&$v 28 | echo foo 3 >&$v 29 | 30 | oclosev 31 | 32 | exec {v}<$SHELLSFILE 33 | echo $v 34 | 35 | while read line <&$v 36 | do 37 | echo $line 38 | done 39 | 40 | iclosev 41 | 42 | type oclosev 43 | type iclosev 44 | 45 | while read -r -u ${fd} 46 | do 47 | echo $REPLY 48 | done {fd}<$SHELLSFILE 49 | 50 | rm -f $SHELLSFILE 51 | 52 | exit 0 53 | -------------------------------------------------------------------------------- /examples/functions/exitstat: -------------------------------------------------------------------------------- 1 | # Contributed by Noah Friedman and Roland McGrath. 2 | 3 | # To be run by the PROMPT_COMMAND variable, so that one can see what 4 | # the exit status of processes are. 5 | 6 | function check_exit_status () 7 | { 8 | local status="$?" 9 | local signal="" 10 | 11 | if [ ${status} -ne 0 ] && [ ${status} != 128 ]; then 12 | # If process exited by a signal, determine name of signal. 13 | if [ ${status} -gt 128 ]; then 14 | signal="$(builtin kill -l $((${status} - 128)) 2>/dev/null)" 15 | if [ "$signal" ]; then signal="($signal)"; fi 16 | fi 17 | echo "[Exit ${status} ${signal}]" 1>&2 18 | fi 19 | return 0 20 | } 21 | 22 | PROMPT_COMMAND=check_exit_status 23 | -------------------------------------------------------------------------------- /tests/attr.tests: -------------------------------------------------------------------------------- 1 | a=(outside) 2 | 3 | f1() { readonly a=(1) ; } 4 | f2() { readonly -a a=(2) ; } 5 | f3() { readonly 'a=(3)' ; } 6 | f4() { readonly -a 'a=(4)' ; } 7 | 8 | f1 9 | echo -n after f1: 10 | declare -p a 11 | f2 12 | echo -n after f2: 13 | declare -p a 14 | f3 15 | echo -n after f3: 16 | declare -p a 17 | f4 18 | echo -n after f4: 19 | declare -p a 20 | 21 | b=(outside) 22 | c=(outside) 23 | d=(outside) 24 | 25 | f2() { readonly -a b=(2) ; } 26 | f3() { readonly 'c=(3)' ; } 27 | f4() { readonly -a 'd=(4)' ; } 28 | 29 | f2 30 | echo -n after f2: 31 | declare -p b 32 | f3 33 | echo -n after f3: 34 | declare -p c 35 | f4 36 | echo -n after f4: 37 | declare -p d 38 | 39 | ${THIS_SH} ./attr1.sub 40 | ${THIS_SH} ./attr2.sub 41 | 42 | -------------------------------------------------------------------------------- /tests/extglob1.sub: -------------------------------------------------------------------------------- 1 | MYDIR=$PWD 2 | 3 | : ${TMPDIR:=/tmp} 4 | GDIR=$TMPDIR/gtest-$$ 5 | 6 | shopt -s extglob 7 | 8 | mkdir $GDIR || exit 1 9 | cd $GDIR || exit 1 10 | 11 | touch a.c 12 | 13 | echo +([[:alpha:].]) 14 | echo +([[:alpha:].])+([[:alpha:].]) 15 | echo *([[:alpha:].]) 16 | echo *([[:alpha:].])*([[:alpha:].]) 17 | 18 | echo ?([[:alpha:].])?([[:alpha:].])?([[:alpha:].]) 19 | echo @([[:alpha:].])@([[:alpha:].])@([[:alpha:].]) 20 | 21 | case . in 22 | !([[:alpha:].]) ) echo bad 1;; 23 | *) echo ok 1;; 24 | esac 25 | 26 | case . in 27 | ?([[:alpha:].]) ) echo ok 2;; 28 | *) echo bad 2;; 29 | esac 30 | 31 | case . in 32 | @([[:alpha:].]) ) echo ok 3;; 33 | *) echo bad 3;; 34 | esac 35 | 36 | cd "$MYDIR" 37 | rm -rf $GDIR 38 | -------------------------------------------------------------------------------- /tests/rsh.right: -------------------------------------------------------------------------------- 1 | ./rsh.tests: line 9: cd: restricted 2 | ./rsh.tests: line 10: PATH: readonly variable 3 | ./rsh.tests: line 11: SHELL: readonly variable 4 | ./rsh.tests: line 12: /bin/sh: restricted: cannot specify `/' in command names 5 | ./rsh.tests: line 14: .: ./source.sub3: restricted 6 | ./rsh.tests: line 17: /tmp/restricted: restricted: cannot redirect output 7 | ./rsh.tests: line 21: /tmp/restricted: restricted: cannot redirect output 8 | ./rsh.tests: line 26: command: -p: restricted 9 | ./rsh.tests: line 28: set: +r: invalid option 10 | set: usage: set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...] 11 | ./rsh.tests: line 29: set: restricted: invalid option name 12 | ./rsh.tests: line 31: exec: restricted 13 | ./rsh.tests: after exec 14 | -------------------------------------------------------------------------------- /tests/comsub-eof.right: -------------------------------------------------------------------------------- 1 | ./comsub-eof0.sub: line 1: unexpected EOF while looking for matching `)' 2 | ./comsub-eof0.sub: line 5: syntax error: unexpected end of file 3 | hi 4 | ./comsub-eof2.sub: line 2: warning: here-document at line 1 delimited by end-of-file (wanted `EOF') 5 | hi 6 | ./comsub-eof3.sub: line 1: unexpected EOF while looking for matching `)' 7 | ./comsub-eof3.sub: line 5: syntax error: unexpected end of file 8 | ./comsub-eof4.sub: line 6: warning: here-document at line 4 delimited by end-of-file (wanted `EOF') 9 | contents 10 | ./comsub-eof5.sub: line 8: warning: here-document at line 6 delimited by end-of-file (wanted `)') 11 | hi 12 | ./comsub-eof5.sub: line 13: warning: here-document at line 11 delimited by end-of-file (wanted `EOF') 13 | hi 14 | -------------------------------------------------------------------------------- /examples/functions/basename: -------------------------------------------------------------------------------- 1 | # Date: Fri, 11 Oct 91 11:22:36 edt 2 | # From: friedman@gnu.ai.mit.edu 3 | # To: bfox@gnu.ai.mit.edu 4 | 5 | # A replacement for basename(1). Not all the systems I use have this 6 | # program. Usage: basename [path] {extension} 7 | function basename () 8 | { 9 | local path="$1" 10 | local suffix="$2" 11 | local tpath="${path%/}" 12 | 13 | # Strip trailing '/' characters from path (unusual that this should 14 | # ever occur, but basename(1) seems to deal with it.) 15 | while [ "${tpath}" != "${path}" ]; do 16 | tpath="${path}" 17 | path="${tpath%/}" 18 | done 19 | 20 | path="${path##*/}" # Strip off pathname 21 | echo ${path%${suffix}} # Also strip off extension, if any. 22 | } 23 | 24 | -------------------------------------------------------------------------------- /tests/source6.sub: -------------------------------------------------------------------------------- 1 | # tests sourcing non-regular files, fixed post-3.2 2 | 3 | : ${TMPDIR:=/tmp} 4 | 5 | TMPFN=$TMPDIR/foo-$$ 6 | 7 | rm -f $TMPFN 8 | echo "echo one - OK" > $TMPFN 9 | . $TMPFN 10 | echo $? 11 | rm -f $TMPFN 12 | 13 | # non-regular readable file 14 | . /dev/null 15 | echo $? 16 | 17 | # FIFO or pipe via /dev/fd 18 | . <(echo "echo two - OK") 19 | echo $? 20 | 21 | # pipe 22 | if [ -e /dev/stdin ]; then 23 | echo "echo three - OK" | . /dev/stdin 24 | echo $? 25 | else 26 | # no /dev/stdin, just fake it 27 | echo "three - OK" ; echo 0 28 | fi 29 | 30 | # FIFO 31 | mkfifo $TMPDIR/fifo-$$ 32 | echo "echo four - OK" > $TMPDIR/fifo-$$ & 33 | sleep 1 # allow the child echo to execute 34 | . $TMPDIR/fifo-$$ 35 | echo $? 36 | rm -f $TMPDIR/fifo-$$ 37 | -------------------------------------------------------------------------------- /po/Rules-builtins: -------------------------------------------------------------------------------- 1 | # 2 | # Update the strings from the builtins' long docs. Must be called when 3 | # bash.pot exists, in the middle of the bash.pot-update recipe 4 | # 5 | builtins.pot-update: $(top_builddir)/builtins/builtins.c 6 | $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_builddir)/builtins \ 7 | $(XGETTEXT_OPTIONS) --omit-header \ 8 | --copyright-holder='$(COPYRIGHT_HOLDER)' \ 9 | --join-existing \ 10 | builtins.c 11 | 12 | # This rule has no dependencies: we don't need to update builtins.pot at 13 | # every "make" invocation, only create it when it is missing. 14 | # Only "make builtins.pot-update" or "make dist" will force an update. 15 | $(srcdir)/builtins.pot: 16 | $(MAKE) builtins.pot-update 17 | 18 | xdist: 19 | $(MAKE) update-po 20 | -------------------------------------------------------------------------------- /tests/new-exp5.sub: -------------------------------------------------------------------------------- 1 | x=(one two) 2 | echo ${x[@]:1} 3 | echo ${x[@]:0:1} 4 | 5 | x=(one) 6 | echo ${x[0]:1} 7 | echo ${x[0]:0} 8 | echo ${x[@]:1} 9 | echo ${x[@]:0} 10 | 11 | echo ${x[@]: -1} 12 | echo ${x[@]: ${#x[@]}-1} 13 | 14 | x=(0 1 2 3 4 5 6 7 8 9) 15 | echo ${x[@]:1} 16 | 17 | echo ${x[@]: -1} 18 | echo ${x[@]: ${#x[@]}-1} 19 | 20 | set -- ${x[@]} 21 | 22 | echo $1 23 | echo ${@: -1} 24 | echo ${@: $#-1} 25 | 26 | a=0123456789 27 | 28 | echo ${a:1} 29 | echo ${a: -1} 30 | echo ${a: ${#a}-1} 31 | 32 | # problem with bash through 3.2.33 33 | oIFS="$IFS" 34 | IFS=$'\n' 35 | a=(A B C D) 36 | b=("${a[@]}") 37 | echo "${#b[@]}", "${b[@]}" # 4, A B C D -- OK 38 | b=("${a[@]:2}") 39 | echo "${#b[@]}", "${b[@]}" # 1, C D -- bug, should be 2, C D 40 | IFS="$oIFS" 41 | -------------------------------------------------------------------------------- /tests/posixexp2.right: -------------------------------------------------------------------------------- 1 | 1 }z 2 | 2 ''z} 3 | 3 foo 'bar baz 4 | 4 foo b c baz 5 | 5 foo b c baz 6 | 6 }z 7 | 7 }z 8 | 8 ""z} 9 | 9 "}"z 10 | 10 foo bar} baz 11 | 11 ''z} 12 | 12 }z 13 | 13 }z 14 | 14 }z 15 | 15 <}> . 16 | 16 hi there 17 | 17 hi there 18 | 18 hi there 19 | 19 hi there 20 | 20 hi there 21 | 21 hi there 22 | 22 hi there 23 | 23 hi there 24 | 24 'value' 25 | 25 'value' 26 | 26 $key 27 | 27 'value' 28 | 28 'x ~ x''x}"x}" # 29 | 29 <{}b> <}> . 30 | 30 . 32 | 32 . 33 | 33 . 34 | 34 . 35 | 35 . 36 | 36 . 37 | 37 . 38 | 38 xay / x'a'y . 39 | 39 x' / x' . 40 | 40 < b c> . 41 | -------------------------------------------------------------------------------- /po/insert-header.sin: -------------------------------------------------------------------------------- 1 | # Sed script that inserts the file called HEADER before the header entry. 2 | # 3 | # At each occurrence of a line starting with "msgid ", we execute the following 4 | # commands. At the first occurrence, insert the file. At the following 5 | # occurrences, do nothing. The distinction between the first and the following 6 | # occurrences is achieved by looking at the hold space. 7 | /^msgid /{ 8 | x 9 | # Test if the hold space is empty. 10 | s/m/m/ 11 | ta 12 | # Yes it was empty. First occurrence. Read the file. 13 | r HEADER 14 | # Output the file's contents by reading the next line. But don't lose the 15 | # current line while doing this. 16 | g 17 | N 18 | bb 19 | :a 20 | # The hold space was nonempty. Following occurrences. Do nothing. 21 | x 22 | :b 23 | } 24 | -------------------------------------------------------------------------------- /tests/dbg-support.sub: -------------------------------------------------------------------------------- 1 | # This file is intended to be sourced from one of the bashdb test programs 2 | 3 | sourced_fn() { 4 | name="fn2" 5 | echo "SOURCED FN LINENO $LINENO" 6 | 7 | # Print a stack trace 8 | declare -i n 9 | n=${#FUNCNAME[@]} 10 | for (( i=0 ; (( i < $n )) ; i++ )) ; do 11 | local -i j=i+1 12 | [ $j -eq $n ] && j=i # main()'s file is the same as the first caller 13 | echo "FUNCNAME[$i]: ${FUNCNAME[$i]} called from ${BASH_SOURCE[$j]}" \ 14 | "at line ${BASH_LINENO[$i]}" 15 | done 16 | } 17 | 18 | echo "SOURCED LINENO $LINENO" 19 | echo "SOURCED BASH_SOURCE[0]" ${BASH_SOURCE[0]} 20 | sourced_fn 21 | 22 | #;;; Local Variables: *** 23 | #;;; mode:shell-script *** 24 | #;;; eval: (sh-set-shell "bash") *** 25 | #;;; End: *** 26 | 27 | -------------------------------------------------------------------------------- /support/bash.pc.in: -------------------------------------------------------------------------------- 1 | # bash.pc.in 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | includedir=@includedir@ 6 | libdir=@libdir@ 7 | 8 | loadablesdir=@loadablesdir@ 9 | headersdir=${includedir}/@PACKAGE_NAME@ 10 | 11 | LOCAL_CFLAGS = @LOCAL_CFLAGS@ 12 | LOCAL_DEFS = @LOCAL_DEFS@ 13 | CCFLAGS = ${LOCAL_DEFS} ${LOCAL_CFLAGS} 14 | 15 | CC = @CC@ 16 | SHOBJ_CC = @SHOBJ_CC@ 17 | SHOBJ_CFLAGS = @SHOBJ_CFLAGS@ 18 | SHOBJ_LD = @SHOBJ_LD@ 19 | SHOBJ_LDFLAGS = @SHOBJ_LDFLAGS@ 20 | SHOBJ_XLDFLAGS = @SHOBJ_XLDFLAGS@ 21 | SHOBJ_LIBS = @SHOBJ_LIBS@ 22 | 23 | Name: @PACKAGE_NAME@ 24 | Description: Bash headers for bash loadable builtins 25 | Version: @PACKAGE_VERSION@ 26 | Url: @PACKAGE_URL@ 27 | Libs: ${SHOBJ_LIBS} 28 | Cflags: ${SHOBJ_CFLAGS} ${CCFLAGS} -I${headersdir} -I${headersdir}/builtins -I${headersdir}/include 29 | -------------------------------------------------------------------------------- /tests/alias.tests: -------------------------------------------------------------------------------- 1 | # place holder for future alias testing 2 | shopt -s expand_aliases 3 | 4 | # alias/unalias tests originally in builtins.tests 5 | 6 | unalias -a 7 | # this should return success, according to POSIX.2 8 | alias 9 | echo alias: $? 10 | alias foo=bar 11 | unalias foo 12 | # this had better return success, according to POSIX.2 13 | alias 14 | echo alias: $? 15 | 16 | # bug in all versions through bash-2.05b 17 | 18 | unalias qfoo qbar qbaz quux 2>/dev/null 19 | 20 | alias qfoo=qbar 21 | alias qbar=qbaz 22 | alias qbaz=quux 23 | alias quux=qfoo 24 | 25 | qfoo 26 | 27 | unalias qfoo qbar qbaz quux 28 | 29 | unalias -a 30 | 31 | alias foo='echo ' 32 | alias bar=baz 33 | alias baz=quux 34 | 35 | foo bar 36 | 37 | unalias foo bar baz 38 | 39 | ${THIS_SH} ./alias1.sub 40 | ${THIS_SH} ./alias2.sub 41 | -------------------------------------------------------------------------------- /tests/nameref6.sub: -------------------------------------------------------------------------------- 1 | # these should be errors 2 | typeset -n x=x 3 | #echo $x -- $? 4 | 5 | typeset -n x[3]=x 6 | #echo $x -- $? 7 | 8 | x=(the browns suck) 9 | y=(one two three) 10 | # should be an error but not disturb the current contents of x 11 | # maybe rethink that later 12 | typeset -n x=y 13 | echo $x -- $? 14 | 15 | typeset -n 16 | 17 | unset x y 18 | 19 | y=42 20 | typeset -i x=1 21 | 22 | # the integer attribute causes arithmetic eval to be done 23 | # we should not allow namerefs to non-identifiers 24 | typeset -n x=y 25 | echo $x -- $? 26 | 27 | typeset +n x 28 | echo $x -- $? 29 | 30 | # same kind of thing 31 | 32 | unset -n x 33 | unset y 34 | 35 | set -- first second third 36 | y=2 37 | typeset -i x=1 38 | 39 | typeset -n x=y 40 | echo $x -- $? 41 | echo ${x} -- $? 42 | 43 | typeset +n x 44 | echo $x -- $? 45 | -------------------------------------------------------------------------------- /tests/comsub.right: -------------------------------------------------------------------------------- 1 | ./comsub.tests: line 7: hijkl: command not found 2 | argv[1] = 3 | argv[2] = 4 | argv[1] = 5 | argv[2] = 6 | argv[1] = 7 | argv[1] = 8 | argv[2] = 9 | argv[1] = <$> 10 | argv[2] = 11 | argv[1] = <`> 12 | argv[2] = 13 | argv[1] = <\> 14 | argv[2] = 15 | argv[1] = 16 | argv[1] = 17 | argv[1] = argv[2] = <-e> argv[3] = 18 | argv[1] = argv[2] = <-e> argv[3] = 19 | argv[1] = 20 | argv[1] = 21 | argv[1] = 22 | #esac 23 | a 24 | ok 1 25 | ok 2 26 | ok 3 27 | ok 4 28 | ok 5 29 | ok 6 30 | xyz 31 | \/tmp\/foo\/bar 32 | /tmp/foo/bar 33 | /tmp/foo/bar 34 | /tmp/foo/bar 35 | 1 36 | 2 37 | 3 38 | 4 39 | 5 40 | 6 41 | 5 42 | 6 43 | a 44 | b 45 | c 46 | a 47 | b 48 | c 49 | 1 50 | 2 51 | -------------------------------------------------------------------------------- /tests/set-x.right: -------------------------------------------------------------------------------- 1 | + (( i=0 )) 2 | + (( i<=5 )) 3 | + x=0 4 | + (( i++ )) 5 | + (( i<=5 )) 6 | + x=0 7 | + (( i++ )) 8 | + (( i<=5 )) 9 | + x=0 10 | + (( i++ )) 11 | + (( i<=5 )) 12 | + x=0 13 | + (( i++ )) 14 | + (( i<=5 )) 15 | + x=0 16 | + (( i++ )) 17 | + (( i<=5 )) 18 | + x=0 19 | + (( i++ )) 20 | + (( i<=5 )) 21 | + for i in 0 1 2 22 | + x=i 23 | + for i in 0 1 2 24 | + x=i 25 | + for i in 0 1 2 26 | + x=i 27 | + case x in 28 | + x=i 29 | + set +x 30 | 1 31 | 2 32 | 3 33 | 4 34 | + for f in a b c d e 35 | + echo a 36 | a 37 | + for f in a b c d e 38 | + echo b 39 | b 40 | + for f in a b c d e 41 | + echo c 42 | c 43 | + for f in a b c d e 44 | + echo d 45 | d 46 | + for f in a b c d e 47 | + echo e 48 | e 49 | + set +x 50 | TRACEFILE: 51 | + echo 1 52 | + echo 2 53 | + echo 3 54 | + echo 4 55 | + unset BASH_XTRACEFD 56 | ===== 57 | -------------------------------------------------------------------------------- /tests/dollar-at-star3.sub: -------------------------------------------------------------------------------- 1 | unset f ; f=abcd 2 | 3 | first_char=${f[@]:0:1} 4 | recho $first_char 5 | 6 | first_char=${f[0]:0:1} 7 | recho $first_char 8 | 9 | first_char=${f:0:1} 10 | recho $first_char 11 | 12 | first_char="${f[@]:0:1}" 13 | recho $first_char 14 | 15 | first_char="${f[@]:0:1}" 16 | recho $first_char 17 | 18 | first_char="${f[0]:0:1}" 19 | recho $first_char 20 | 21 | first_char="${f:0:1}" 22 | recho $first_char 23 | 24 | unset f; 25 | f=( one two three ) 26 | first_word=${f[@]:0:1} 27 | recho $first_word 28 | 29 | first_word=${f[0]:0:1} 30 | recho $first_word 31 | 32 | first_word=${f:0:1} 33 | recho $first_word 34 | 35 | unset f; 36 | f=( one two three ) 37 | first_word=${f[@]:0:1} 38 | recho $first_word 39 | 40 | set -- abc def ghi 41 | 42 | printf '<%s> ' "123 $@ 456"; echo 43 | printf '<%s> ' "123 $@\ 456"; echo 44 | 45 | -------------------------------------------------------------------------------- /examples/loadables/perl/bperl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * perl builtin 3 | */ 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | #include "builtins.h" 10 | #include "shell.h" 11 | 12 | #ifndef errno 13 | extern int errno; 14 | #endif 15 | 16 | extern char **make_builtin_argv (); 17 | extern char **export_env; 18 | 19 | extern int perl_main(); 20 | 21 | bperl_builtin(list) 22 | WORD_LIST *list; 23 | { 24 | char **v; 25 | int c, r; 26 | 27 | v = make_builtin_argv(list, &c); 28 | r = perl_main(c, v, export_env); 29 | free(v); 30 | 31 | return r; 32 | } 33 | 34 | char *bperl_doc[] = { 35 | "An interface to a perl5 interpreter.", 36 | (char *)0 37 | }; 38 | 39 | struct builtin bperl_struct = { 40 | "bperl", 41 | bperl_builtin, 42 | BUILTIN_ENABLED, 43 | bperl_doc, 44 | "bperl [perl options] [file ...]", 45 | 0 46 | }; 47 | -------------------------------------------------------------------------------- /tests/dollar-star7.sub: -------------------------------------------------------------------------------- 1 | # if IFS side effects in ${IFS=} assignments take place, how do you cope with 2 | # later changes to IFS in the same set of expansions? You've already 3 | # committed to using the first character of the (old) IFS to expand $* in 4 | # the previous expansions, and changing it to not include ' ', for instance, 5 | # results in the first couple of ${*} below not being split at all 6 | 7 | set -f -- a b c 8 | 9 | unset -v IFS 10 | printf '<%s> ' ${*}${IFS=}${*}${IFS:=-}"${*}" 11 | echo 12 | printf "after 1: IFS " 13 | echo "${IFS-unset}" 14 | recho "$*" 15 | 16 | set -f -- a 'b c' d 17 | unset -v IFS 18 | printf '<%s> ' ${*}${IFS=}${*}${IFS:=-}"${*}" 19 | echo 20 | printf "after 2: IFS " 21 | echo "${IFS-unset}" 22 | recho "$*" 23 | 24 | unset -v IFS 25 | recho $* 26 | recho "$*" 27 | 28 | IFS=' ' 29 | recho $* 30 | recho "$*" 31 | -------------------------------------------------------------------------------- /tests/getopts5.sub: -------------------------------------------------------------------------------- 1 | #Time-stamp: <95/06/07 07:40:40 hrue@imf.unit.no> 2 | 3 | getop () { 4 | 5 | local OPTIND 6 | local OPTERR=1 7 | 8 | echo getop: OPTERR=$OPTERR 9 | while getopts ab arg "$@"; do 10 | case $arg in 11 | a) 12 | echo a here 13 | ;; 14 | b) 15 | echo b here 16 | ;; 17 | :|?|*) 18 | echo something else here 19 | ;; 20 | esac 21 | done 22 | echo getop: OPTIND=$OPTIND 23 | } 24 | 25 | OPTIND= 26 | OPTERR=0 27 | 28 | echo OPTERR=$OPTERR 29 | while getopts ab arg; do 30 | case $arg in 31 | a) 32 | echo a here 33 | ;; 34 | b) 35 | echo b here 36 | ;; 37 | :|?|*) 38 | 39 | echo something else here 40 | ;; 41 | esac 42 | done 43 | 44 | echo OPTIND=$OPTIND 45 | 46 | getop "$@" -d -e 47 | 48 | echo OPTIND=$OPTIND 49 | echo OPTERR=$OPTERR 50 | -------------------------------------------------------------------------------- /tests/exp6.sub: -------------------------------------------------------------------------------- 1 | recho """"a 2 | recho a"""" 3 | 4 | recho """" 5 | 6 | recho """"b 7 | recho b"""" 8 | 9 | recho """"""c 10 | recho c"""""" 11 | 12 | recho """"""c"""" 13 | recho """"c"""""" 14 | 15 | recho """"""""c 16 | recho c"""""""" 17 | 18 | # BASH BUG: spurious DEL characters appear on empty variable interpolation. 19 | # BASH 4.2.8(1)-release 20 | 21 | a='' 22 | 23 | recho correct "$a" # correct empty output line 24 | recho correct "$a""$a" # correct empty output line 25 | recho correct "$a""$a""$a" # correct empty output line 26 | recho XwrongX "$a""$a""$a""$a" # spurious two DEL chars appear at line end 27 | recho correct a"$a" # correct single "a" on line 28 | recho XwrongX a"$a""$a" # spurious DEL char appears at line end 29 | recho correct a"$a$a" # correct single "a" on line 30 | recho correct a"$a$a$a$a" # correct single "a" on line 31 | -------------------------------------------------------------------------------- /tests/nameref3.sub: -------------------------------------------------------------------------------- 1 | # nameref requires changes to unset 2 | bar=one 3 | typeset -n foo=bar 4 | 5 | # normal unset unsets only variable nameref references 6 | # need unset -n to unset nameref itself 7 | unset foo 8 | echo "expect " 9 | recho ${bar-unset} 10 | echo "expect " 11 | recho ${foo-unset} 12 | echo "expect " 13 | recho ${!foo} 14 | unset -n foo 15 | echo "expect " 16 | recho "${!foo-unset}" 17 | 18 | readonly bar=two 19 | typeset -n foo=bar 20 | 21 | unset foo # this should fail because bar is readonly 22 | 23 | echo "expect " 24 | echo ${bar-unset} 25 | echo "expect " 26 | echo ${foo-unset} 27 | 28 | # one question is what happens when you unset the underlying variable 29 | qux=three 30 | typeset -n ref 31 | ref=qux 32 | 33 | echo $ref 34 | unset qux 35 | echo ${ref-unset} 36 | qux=four 37 | echo ${ref-unset} 38 | -------------------------------------------------------------------------------- /lib/malloc/stub.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1993-2003 Free Software Foundation, Inc. 2 | 3 | This file is part of GNU Bash, the Bourne Again SHell. 4 | 5 | Bash is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | Bash is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with Bash. If not, see . 17 | */ 18 | 19 | void 20 | bash_malloc_stub() 21 | { 22 | } 23 | -------------------------------------------------------------------------------- /tests/varenv4.sub: -------------------------------------------------------------------------------- 1 | f() 2 | { 3 | local -a v 4 | local -a w 5 | 6 | g 7 | echo "f: ${v[@]}, ${w[@]}" 8 | } 9 | 10 | g() 11 | { 12 | aux=v 13 | declare -ga "$aux=( asdf fdsa )" 14 | declare -ga w=( asdf fdsa ) 15 | 16 | echo "g: ${v[@]}, ${w[@]}" 17 | } 18 | 19 | f 20 | echo "FIN: ${v[@]}, ${w[@]}" 21 | 22 | unset v w 23 | unset -f f g 24 | 25 | f() 26 | { 27 | local v 28 | local w 29 | 30 | g 31 | echo f: v = $v, w = $w 32 | } 33 | 34 | g() 35 | { 36 | aux=v 37 | declare -g w=one 38 | declare -g "$aux=two" 39 | 40 | echo g: v = $v, w = $w 41 | } 42 | 43 | f 44 | echo FIN: v = $v, w = $w 45 | 46 | # problem with error return propagation through bash-4.3 47 | unset -f aaa bbb 48 | unset unique 49 | 50 | aaa() { 51 | declare -g -a unique=() 52 | } 53 | bbb() { 54 | declare -g -A unique=() 55 | } 56 | aaa 57 | bbb 58 | echo after bbb: $? 59 | -------------------------------------------------------------------------------- /tests/cond-regexp2.sub: -------------------------------------------------------------------------------- 1 | [[ "\\" =~ ["."] ]] && echo bad 1 2 | 3 | [[ "\\" =~ "[.]" ]] && echo bad 2 4 | 5 | [[ "\\" =~ [\. ]] && echo bad 3 6 | 7 | [[ "\\" =~ [\.] ]] && echo bad 4 8 | 9 | [[ "\\" =~ [\\] ]] || echo bad 5 10 | 11 | [[ dog =~ [[=d=]].. ]] && echo ok 1 12 | [[ d.. =~ [[=d=]]\.\. ]] && echo ok 2 13 | [[ dog =~ ['[=d=]'].. ]] && echo ok 3 # dubious 14 | 15 | [[ dog =~ [[=d=]].[[=G=][=g=]] ]] && echo ok 4 16 | [[ dog =~ [[=d=]].[\[=G=][=g=]] ]] && echo ok 4a 17 | 18 | [[ dog =~ "d.." ]] || echo ok 5 19 | 20 | [[ dog =~ [[.d.][.D.]]o. ]] && echo ok 6 21 | 22 | [[ dog =~ ([[.d.][.D.]])o(.) ]] && echo ok 7 -- ${BASH_REMATCH[1]} 23 | [[ dog =~ d([[.o.][.O.]])(.) ]] && echo ok 8 -- ${BASH_REMATCH[1]} 24 | [[ dog =~ .([[.o.][.O.]])(.) ]] && echo ok 9 25 | 26 | [[ dog =~ 'd''o''g' ]] && echo ok 10 27 | 28 | [[ ']' =~ [']'] ]] && echo ok 11 29 | 30 | [[ a =~ ['a]'] ]] || echo ok 12 31 | -------------------------------------------------------------------------------- /tests/func3.sub: -------------------------------------------------------------------------------- 1 | # 2 | # test some posix-mode-specific function behavior 3 | # 4 | set -o posix 5 | func() 6 | { 7 | return 5 8 | } 9 | 10 | myfunction () { 11 | var=20 return 12 | } 13 | var=10 14 | echo expect 5 10 15 | func 16 | echo $? $var 17 | 18 | myfunction 19 | echo expect 20 20 | echo $var 21 | 22 | echo expect 5 20 23 | func 24 | echo $? $var 25 | 26 | echo expect 5 30 27 | var=30 func 28 | echo $? $var 29 | 30 | : ${TMPDIR:=/tmp} 31 | TMPFILE=$TMPDIR/func3.sub.$$ 32 | 33 | rm -f $TMPFILE 34 | echo 'var=40 return 2' > $TMPFILE 35 | 36 | # test the behavior of `return' and preceding variable assignments here 37 | # because it's convenient 38 | var=10 39 | echo expect 2 40 40 | . $TMPFILE 41 | echo $? $var 42 | 43 | rm -f $TMPFILE 44 | 45 | #set -o posix 46 | var=0 47 | func() 48 | { 49 | var=20 return 5 50 | } 51 | 52 | echo expect 5 20 53 | var=30 func 54 | echo $? $var 55 | -------------------------------------------------------------------------------- /tests/builtins6.sub: -------------------------------------------------------------------------------- 1 | f1() 2 | { 3 | echo f1 4 | } 5 | 6 | f2() 7 | { 8 | echo f2 9 | } 10 | 11 | v1=one 12 | v2=two 13 | 14 | echo all set: 15 | 16 | echo ${v1-unset1} 17 | echo ${v2-unset2} 18 | 19 | declare -f -p f1 f2 20 | 21 | unset v1 f1 v2 f2 22 | 23 | echo all unset: 24 | 25 | echo ${v1-unset1} 26 | echo ${v2-unset2} 27 | 28 | declare -f -p f1 f2 29 | 30 | f1() 31 | { 32 | echo f1 33 | } 34 | 35 | f2() 36 | { 37 | echo f2 38 | } 39 | 40 | v1=one-one 41 | v2=two-one 42 | 43 | echo all reset: 44 | echo ${v1-unset1} 45 | echo ${v2-unset2} 46 | 47 | declare -f -p f1 f2 48 | 49 | unset -v v1 f1 v2 f2 50 | 51 | echo vars unset: 52 | 53 | echo ${v1-unset1} 54 | echo ${v2-unset2} 55 | 56 | declare -f -p f1 f2 57 | 58 | v1=one-two 59 | v2=two-two 60 | 61 | unset -f v1 f1 v2 f2 62 | 63 | echo funcs unset: 64 | 65 | echo ${v1-unset1} 66 | echo ${v2-unset2} 67 | 68 | declare -f f1 f2 69 | -------------------------------------------------------------------------------- /tests/func1.sub: -------------------------------------------------------------------------------- 1 | # 2 | # Test that redirections attached to shell functions are printed correctly. 3 | # This was a bug in all bash versions before bash-2.04. 4 | # 5 | f() 6 | { 7 | echo f-x 8 | echo f-y 9 | } >&2 10 | 11 | type f 12 | export -f f 13 | ${THIS_SH} -c 'echo subshell; type f' 14 | 15 | f2() 16 | { 17 | echo f2-a 18 | f3() 19 | { 20 | echo f3-a 21 | echo f3-b 22 | } >&2 23 | f3 24 | } 25 | 26 | type f2 27 | 28 | export -f f2 29 | ${THIS_SH} -c 'echo subshell; type f2' 30 | 31 | f4() 32 | { 33 | echo f4-a 34 | f5() 35 | { 36 | echo f5-a 37 | echo f5-b 38 | } >&2 39 | f5 40 | } 2>&1 41 | 42 | type f4 43 | export -f f4 44 | ${THIS_SH} -c 'echo subshell; type f4' 45 | 46 | testgrp() 47 | { 48 | echo testgrp-a 49 | { echo tg-x; echo tg-y; } >&2 50 | echo testgrp-b 51 | } 52 | type testgrp 53 | 54 | export -f testgrp 55 | ${THIS_SH} -c 'echo subshell; type testgrp' 56 | -------------------------------------------------------------------------------- /tests/source7.sub: -------------------------------------------------------------------------------- 1 | shopt -s expand_aliases 2 | 3 | : ${TMPDIR:=/var/tmp} 4 | 5 | echo '((echo abc; echo def;); echo ghi)' > $TMPDIR/x28-$$ 6 | . $TMPDIR/x28-$$ 7 | rm -f $TMPDIR/x28-$$ 8 | 9 | echo after 10 | 11 | TMPFILE=$TMPDIR/x29-$$ 12 | 13 | echo "#! ${THIS_SH}" >$TMPFILE 14 | cat >> $TMPFILE << \EOF 15 | 16 | (echo -n "$1 "; echo subshell) 17 | EOF 18 | chmod 755 $TMPFILE 19 | 20 | alias foo1='$TMPFILE one.1; source $TMPFILE two.1; source $TMPFILE three.1; $TMPFILE four.1' 21 | alias foo2='$TMPFILE one.2; 22 | source $TMPFILE two.2; 23 | source $TMPFILE three.2; 24 | $TMPFILE four.2; 25 | ' 26 | 27 | foo1 28 | foo2 29 | 30 | echo x29 - done 31 | rm -f $TMPFILE 32 | 33 | # this is also treated similarly to an alias expansion internally 34 | ((echo abc; echo def;); echo ghi) 35 | 36 | if (((4+4) + (4 + 7))); then 37 | echo ok 38 | fi 39 | 40 | (()) # make sure the null expression works OK 41 | -------------------------------------------------------------------------------- /tests/set-e.right: -------------------------------------------------------------------------------- 1 | 95 2 | 96 3 | 97 4 | 98 5 | 99 6 | 0 7 | 1 8 | 2 9 | 3 10 | 4 11 | 5 12 | 6 13 | 7 14 | 8 15 | 9 16 | 1 17 | 1 18 | ok 19 | hi 20 | while succeeded 21 | until succeeded: 4 22 | if succeeded 23 | AND list succeeded 24 | OR list succeeded 25 | ! succeeded 26 | eval succeeded 27 | ! eval succeeded -- 1 28 | ! eval succeeded -- 2 29 | a 30 | 0 31 | b 32 | 0 33 | after 1 34 | a 35 | 0 36 | non-posix foo 37 | after brace group failure: 1 38 | A 1 39 | B 0 40 | C 0 41 | D 0 42 | D 1 43 | A 1 44 | B 0 45 | C 0 46 | D 0 47 | D 1 48 | A 1 49 | B 0 50 | C 0 51 | A 1 52 | B 1 53 | C 0 54 | B 0 55 | C 0 56 | after negation 1: 0 57 | after negation 2: 0 58 | after negation 3: 1 59 | after negation 4: 0 60 | after brace pipeline 61 | foo 62 | after failure 1 63 | after failure 2 64 | after failure 3 65 | true || false no exit 66 | false || true no exit 67 | false && false no exit 68 | A: 69 | B: 70 | ehB 71 | C: 72 | D: 73 | -------------------------------------------------------------------------------- /tests/array20.sub: -------------------------------------------------------------------------------- 1 | # tests to make sure that $* and ${array[*]} expand consistently in `list' 2 | # and `scalar' contexts 3 | 4 | arr=(a b c) 5 | IFS=+ 6 | 7 | # these two should both expand to `+' separated strings 8 | a=${arr[*]} ; echo "$a" 9 | b=${arr[*]/a/x}; echo "$b" 10 | 11 | set -- a b c 12 | 13 | # these two should both expand to `+' separated strings 14 | a=${*} ; echo "$a" 15 | b=${*/a/x}; echo "$b" 16 | 17 | # these two should both expand to `+' separated strings and it should handle 18 | # characters in IFS as chars in the string 19 | unset a b 20 | 21 | set -- 'a+b' 'c+d' 'e+f' 22 | a=${*} ; recho "$a" 23 | b=${*/a/x}; recho "$b" 24 | 25 | # now let's make sure that @ always uses space separators even in contexts 26 | # where we don't do word splitting 27 | set -- a b c 28 | a=${@} ; echo "$a" 29 | b=${@/a/x}; echo "$b" 30 | 31 | unset a b 32 | 33 | a=${arr[@]} ; echo "$a" 34 | b=${arr[@]/a/x}; echo "$b" 35 | -------------------------------------------------------------------------------- /tests/nameref8.sub: -------------------------------------------------------------------------------- 1 | function f1 2 | { 3 | typeset -n v=$1 4 | 5 | v=inside 6 | } 7 | 8 | v=global 9 | f1 v 10 | echo $v 11 | 12 | unset v 13 | unset -f f1 14 | 15 | function foo 16 | { 17 | typeset x=one 18 | 19 | typeset -n y=$1 20 | y=two 21 | echo inside: $x 22 | } 23 | 24 | foo x 25 | echo outside: $x 26 | 27 | function foo2 28 | { 29 | typeset -n x=$1 30 | 31 | x=foo 32 | } 33 | 34 | foo2 x 35 | echo $x 36 | 37 | unset -f foo 38 | function foo { typeset -n v=$1; v=local; } 39 | 40 | v=global 41 | foo v 42 | echo $v 43 | 44 | unset v 45 | 46 | # invalid self reference at global scope 47 | typeset -n v=v 48 | 49 | # can we catch a circular self-reference? 50 | typeset -n v=w 51 | typeset -n w=x 52 | typeset -n x=v 53 | 54 | x=4 55 | echo x = $x 56 | 57 | unset -n v w x 58 | 59 | # can we keep local variables invisible when we add nameref attribute? 60 | function f { typeset x; typeset -n x; x=y; } 61 | f 62 | -------------------------------------------------------------------------------- /tests/redir8.sub: -------------------------------------------------------------------------------- 1 | cd ${TMPDIR:=/var/tmp} 2 | rm -f u 3 | 4 | ${THIS_SH} -c 'exec 10>&1; echo fd 10 >&10' 10>u 5 | cat u 6 | rm -f u 7 | 8 | ${THIS_SH} -c 'exec 8>&1; echo fd 8 >&8' 8>u 9 | cat u 10 | rm -f u 11 | 12 | exec 10>u 13 | exec 10>&1; echo 'fd 10' >&10 14 | cat u 15 | rm -f u 16 | exec 10>&- 17 | 18 | exec 8>u 19 | exec 8>&1; echo 'fd 8' >&8 20 | cat u 21 | rm -f u 22 | exec 8>&- 23 | 24 | rm -f infile 25 | cat > infile <. 20 | # 21 | 22 | if [ "$1" = '-y' ]; then 23 | shift 24 | fi 25 | 26 | exec /usr/bin/yacc ${1+"$@"} 27 | -------------------------------------------------------------------------------- /tests/attr1.sub: -------------------------------------------------------------------------------- 1 | m=1 2 | readonly m=4 3 | declare -p m 4 | 5 | n=1 6 | f() { readonly n=4; echo -n in func: ; declare -p n ; } 7 | f 8 | declare -p n 9 | 10 | p=1 11 | readonly p 12 | 13 | readonly p=4 14 | declare -p p 15 | 16 | r=(1) 17 | readonly r 18 | 19 | f() { readonly r=(4) ; } 20 | f 21 | declare -p r 22 | 23 | f() { readonly r='(5)' ; } 24 | f 25 | declare -p r 26 | 27 | f() { readonly -a r=(6) ; } 28 | f 29 | declare -p r 30 | 31 | f() { readonly -a r='(7)' ; } 32 | f 33 | declare -p r 34 | 35 | x=(1) 36 | readonly x=(4) 37 | declare -p x 38 | 39 | y=(1) 40 | f() { readonly y=(4); echo -n in func: ; declare -p y; } 41 | f 42 | declare -p y 43 | 44 | z=(1) 45 | f() { readonly -a z=(4); echo -n in func: ; declare -p z; } 46 | f 47 | declare -p z 48 | 49 | f() { readonly y1=(4); echo -n in func: ; declare -p y1; } 50 | f 51 | declare -p y1 52 | 53 | f() { readonly -a z1=(4); echo -n in func: ; declare -p z1; } 54 | f 55 | declare -p z1 56 | -------------------------------------------------------------------------------- /tests/nameref18.sub: -------------------------------------------------------------------------------- 1 | declare -n ref=XXX[0] 2 | mapfile ref <<< $'1\n2' 3 | declare -p XXX[0] 4 | 5 | unset -n ref 6 | 7 | declare -n ref=XXX[0] 8 | declare -A ref 9 | ref[foo]=bar 10 | declare -p XXX[0] 11 | 12 | unset -n ref 13 | unset XXX 14 | 15 | typeset -n ref=XXX[0] 16 | typeset ref=4 17 | 18 | typeset -p ref XXX 19 | 20 | unset -n ref 21 | unset XXX 22 | 23 | declare -n ref=XXX[0] 24 | ref+=([2]=x) 25 | declare -p ref XXX[0] 26 | unset -n ref 27 | 28 | declare -n ref=XXX[0] 29 | read -a ref <<< "A B C" 30 | declare -p XXX[0] 31 | unset -n ref 32 | 33 | declare -n ref=XXX[0] 34 | unset ref 35 | ref=() 36 | declare -p ref 37 | 38 | coproc ref { :; }; declare -p ${!ref} 39 | wait 40 | 41 | unset -n ref 42 | 43 | declare -n ref=var[123] 44 | unset ref 45 | declare ref= 46 | declare -p ref ${!ref} var 47 | 48 | unset ref 49 | declare ref+= 50 | declare -p ref ${!ref} var 51 | 52 | declare +t ref 53 | ref=X 54 | declare -p ref ${!ref} var 55 | -------------------------------------------------------------------------------- /tests/run-all: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | : ${TMPDIR:=/tmp} 4 | export TMPDIR 5 | 6 | # basic /bin/sh syntax 7 | SUFFIX=`${THIS_SH} -c 'echo $(( $RANDOM + $BASHPID ))'` 8 | 9 | BASH_TSTOUT=${TMPDIR}/bashtst-$SUFFIX # for now 10 | export BASH_TSTOUT 11 | 12 | trap 'rm -f $BASH_TSTOUT' 0 13 | 14 | PATH=.:$PATH # just to get recho/zecho/printenv if not run via `make tests' 15 | export PATH 16 | 17 | # unset BASH_ENV only if it is set 18 | [ "${BASH_ENV+set}" = "set" ] && unset BASH_ENV 19 | # ditto for SHELLOPTS 20 | #[ "${SHELLOPTS+set}" = "set" ] && unset SHELLOPTS 21 | 22 | : ${THIS_SH:=../bash} 23 | export THIS_SH 24 | 25 | ${THIS_SH} ./version 26 | 27 | rm -f ${BASH_TSTOUT} 28 | 29 | echo Any output from any test, unless otherwise noted, indicates a possible anomaly 30 | 31 | for x in run-* 32 | do 33 | case $x in 34 | $0|run-minimal|run-gprof) ;; 35 | *.orig|*~) ;; 36 | *) echo $x ; sh $x ; rm -f ${BASH_TSTOUT} ;; 37 | esac 38 | done 39 | 40 | exit 0 41 | -------------------------------------------------------------------------------- /tests/iquote1.sub: -------------------------------------------------------------------------------- 1 | # Problems with variables that expand to 0x7f and quoted nulls in the same 2 | # expansion -- affects bash versions 4.0-post 4.2 3 | a=x 4 | b= 5 | del=$'\x7f' 6 | 7 | set "" 8 | 9 | recho ${undef-"x$*y"} 10 | recho "x$*y" 11 | recho x"$*"y 12 | recho x"$del"y 13 | 14 | recho ${undef-"$@"} 15 | recho "$@" 16 | recho "${@}" 17 | recho ${undef-"$*"} 18 | recho "$*" 19 | recho "${*}" 20 | 21 | recho "$del${a#x}" 22 | recho "$del ${a#x}" 23 | recho " $del${a#x}" 24 | 25 | recho " $del$b" 26 | recho " $del${b}" 27 | recho " $del${b#x}" 28 | recho " $del${a#x}" 29 | 30 | recho " $del${a%x}" 31 | recho " $del${a:0:0}" 32 | recho " $del"${a:0:0} 33 | recho " $del""${a:0:0}" 34 | recho " $del${a}" 35 | recho " $del" 36 | recho " ${del}${a:0:0}" 37 | recho " ${del:0:1}${a:0:0}" 38 | recho " ${del:0:1}${a}" 39 | recho "${del:0:1}${a#d}" 40 | recho "${del:0:1}${a#x}" 41 | recho " ${del:0:1} ${a}" 42 | recho "${del:0:1} ${a#d}" 43 | recho "${del:0:1} ${a#x}" 44 | -------------------------------------------------------------------------------- /tests/unicode2.sub: -------------------------------------------------------------------------------- 1 | . ./test-glue-functions 2 | 3 | export LANG=en_US.UTF-8 4 | 5 | printf '%s\n' "$(printf '\uff')" | od -b | _intl_normalize_spaces 6 | printf '%s\n' $'\uff' | od -b | _intl_normalize_spaces 7 | 8 | printf '\uff'\\n | od -b | _intl_normalize_spaces 9 | echo $'\uff' | od -b | _intl_normalize_spaces 10 | 11 | printf '\uffff'\\n | od -b | _intl_normalize_spaces 12 | echo $'\uffff' | od -b | _intl_normalize_spaces 13 | 14 | printf '\Ufffffffe'\\n | od -b | _intl_normalize_spaces 15 | echo $'\Ufffffffe' | od -b | _intl_normalize_spaces 16 | 17 | printf '\Uffffffff'\\n | od -b | _intl_normalize_spaces 18 | echo $'\Uffffffff' | od -b | _intl_normalize_spaces 19 | 20 | LC_CTYPE=C printf '\uff'\\n | od -b | _intl_normalize_spaces 21 | LC_CTYPE=ru_RU.CP1251 printf '\uff'\\n | od -b | _intl_normalize_spaces 22 | LC_CTYPE=en_US.UTF-8 printf '\uff'\\n | od -b | _intl_normalize_spaces 23 | 24 | echo -e '\u0041 \u00a3 \u0152' | od -b | _intl_normalize_spaces 25 | -------------------------------------------------------------------------------- /support/printenv.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh - 2 | 3 | # Copyright (C) 1996-2002 Free Software Foundation, Inc. 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | # 18 | 19 | if [ $# -eq 0 ]; then 20 | env 21 | exit 22 | elif eval [ "\${$1-unset}" = "unset" ]; then 23 | exit 1 24 | else 25 | eval echo \$$1 26 | exit 0 27 | fi 28 | -------------------------------------------------------------------------------- /tests/redir4.sub: -------------------------------------------------------------------------------- 1 | minus=- 2 | 3 | # standard input 4 | fd=0 5 | 6 | exec 3<&$fd 7 | 8 | read line <&3 9 | echo from stdin: $line 10 | 11 | # close fd 3 12 | exec 3<&${minus} 13 | 14 | # should give `bad fd', but exact error messages vary 15 | # read line <&3 16 | 17 | # standard output 18 | fd=1 19 | 20 | exec 4>&$fd 21 | 22 | echo to stdout >&4 23 | 24 | exec 4>&$minus 25 | 26 | # should give `bad fd', but exact error messages vary 27 | # echo to stdout >&4 28 | 29 | unset fd 30 | 31 | # these are ambiguous redirects 32 | exec 3<&$fd 33 | exec 4>&$fd 34 | 35 | exec 3>&1 4>&2 36 | 37 | exec >&/tmp/err-and-out 38 | echo to stdout 39 | echo to stderr >&2 40 | 41 | exec 1>&3 2>&4 42 | echo /tmp/err-and-out: 43 | cat /tmp/err-and-out 44 | 45 | rm /tmp/err-and-out 46 | 47 | fd=/tmp/err-and-out 48 | exec >&$fd 49 | echo to stdout 50 | echo to stderr >&2 51 | 52 | exec 1>&3 2>&4 53 | echo /tmp/err-and-out: 54 | cat /tmp/err-and-out 55 | 56 | rm /tmp/err-and-out 57 | -------------------------------------------------------------------------------- /doc/builtins.1: -------------------------------------------------------------------------------- 1 | .\" This is a hack to force bash builtins into the whatis database 2 | .\" and to get the list of builtins to come up with the man command. 3 | .\" 4 | .\" File Name macro. This used to be `.PN', for Path Name, 5 | .\" but Sun doesn't seem to like that very much. 6 | .\" 7 | .de FN 8 | \fI\|\\$1\|\fP 9 | .. 10 | .TH BASH_BUILTINS 1 "2004 Apr 20" "GNU Bash-4.2" 11 | .SH NAME 12 | bash, :, ., [, alias, bg, bind, break, builtin, caller, 13 | cd, command, compgen, complete, 14 | compopt, continue, declare, dirs, disown, echo, enable, eval, exec, exit, 15 | export, false, fc, fg, getopts, hash, help, history, jobs, kill, 16 | let, local, logout, mapfile, popd, printf, pushd, pwd, read, 17 | readonly, return, set, 18 | shift, shopt, source, suspend, test, times, trap, true, type, typeset, 19 | ulimit, umask, unalias, unset, wait \- bash built-in commands, see \fBbash\fR(1) 20 | .SH BASH BUILTIN COMMANDS 21 | .nr zZ 1 22 | .so bash.1 23 | .SH SEE ALSO 24 | bash(1), sh(1) 25 | -------------------------------------------------------------------------------- /tests/redir11.sub: -------------------------------------------------------------------------------- 1 | # make sure redirections do not have access to the temporary environment, even 2 | # in subshells and command substitutions 3 | 4 | a=1 5 | a=4 b=7 ss=4 echo $a 6 | 7 | a=42 8 | a=2 echo foo >&$a 9 | a=2 echo foo >&$(echo $a) 10 | 11 | foo() 12 | { 13 | local -i a 14 | local v=0 x=1 15 | a+=3 16 | echo $a 17 | } 18 | 19 | a=4 b=7 ss=4 declare -i ss 20 | a=4 b=7 foo 21 | echo after: $a 22 | 23 | unset a 24 | a=4 echo foo >&$(foo) 25 | a=1 echo foo >&$(foo) 26 | a=1 echo foo >&$(a=4 foo) 27 | echo foo >&$(a=4 foo) 28 | 29 | a=42 30 | a=2 echo foo >&$a 31 | a=2 echo foo >&$(echo $a) 32 | 33 | unset -f foo 34 | foo() 35 | { 36 | local -i a 37 | local v=0 x=1 38 | a+=3 39 | echo $a >&$(ss= declare -i ss) 40 | } 41 | 42 | a=4 b=7 foo 43 | echo after: $a 44 | 45 | unset a 46 | typeset -i a 47 | a=4 eval echo $(echo a+=3) 48 | a=2 49 | a=9 echo foo >&$(echo $a) 50 | a=2 51 | a=9 eval echo foo >&$(echo $a) 52 | a=2 53 | a=9 eval echo foo '>&$(echo $a)' 54 | -------------------------------------------------------------------------------- /tests/new-exp4.sub: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | arrayA=("A" "B" "C") 4 | 5 | arrayB=( ${arrayA[*]} ) 6 | echo "Case01---${#arrayB[*]}---${arrayB[0]}:${arrayB[1]}:${arrayB[2]}---" 7 | 8 | arrayB=( "${arrayA[*]}" ) 9 | echo "Case02---${#arrayB[*]}---${arrayB[0]}:${arrayB[1]}:${arrayB[2]}---" 10 | 11 | arrayB=( ${arrayA[@]} ) 12 | echo "Case03---${#arrayB[@]}---${arrayB[0]}:${arrayB[1]}:${arrayB[2]}---" 13 | 14 | arrayB=( "${arrayA[@]}" ) 15 | echo "Case04---${#arrayB[@]}---${arrayB[0]}:${arrayB[1]}:${arrayB[2]}---" 16 | 17 | xx="arrayA[*]" 18 | 19 | arrayB=( ${!xx} ) 20 | echo "Case05---${#arrayB[*]}---${arrayB[0]}:${arrayB[1]}:${arrayB[2]}---" 21 | 22 | arrayB=( "${!xx}" ) 23 | echo "Case06---${#arrayB[*]}---${arrayB[0]}:${arrayB[1]}:${arrayB[2]}---" 24 | 25 | xx="arrayA[@]" 26 | 27 | arrayB=( ${!xx} ) 28 | echo "Case07---${#arrayB[@]}---${arrayB[0]}:${arrayB[1]}:${arrayB[2]}---" 29 | 30 | arrayB=( "${!xx}" ) 31 | echo "Case08---${#arrayB[@]}---${arrayB[0]}:${arrayB[1]}:${arrayB[2]}---" 32 | -------------------------------------------------------------------------------- /lib/intl/osdep.c: -------------------------------------------------------------------------------- 1 | /* osdep.c - OS dependent parts of libintl. */ 2 | 3 | /* Copyright (C) 2001-2002, 2005-2009 Free Software Foundation, Inc. 4 | 5 | This file is part of GNU Bash. 6 | 7 | Bash is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Bash is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Bash. If not, see . 19 | */ 20 | 21 | #if defined __EMX__ 22 | # include "os2compat.c" 23 | #else 24 | /* Avoid AIX compiler warning. */ 25 | typedef int dummy; 26 | #endif 27 | -------------------------------------------------------------------------------- /tests/nameref16.sub: -------------------------------------------------------------------------------- 1 | # post-bash-4.3 changes for more ksh93 compatibility when following nameref 2 | # chains and using typeset/declare -n to operate on nameref variables rather 3 | # than the variables they reference 4 | 5 | # don't follow nameref chain when using declare -n and at the global scope 6 | unset -n r1 r2 7 | 8 | typeset -n r1=r2 9 | typeset -n r2=x 10 | typeset -n r1=y 11 | 12 | typeset -p r1 r2 x y 13 | 14 | # same behavior when in a shell function 15 | foo() 16 | { 17 | typeset -n r1=r2 18 | typeset -n r2=x 19 | typeset -n r1=y 20 | 21 | typeset -p r1 r2 x y 22 | } 23 | unset -n r1 r2 24 | foo 25 | unset -f foo 26 | 27 | # same behavior when namerefs aren't chained 28 | unset -n r1 r2 29 | 30 | typeset -n r1=z 31 | typeset -n r2=x 32 | typeset -n r1=y 33 | typeset -p r1 r2 x y 34 | 35 | # same behavior when referenced variables have values 36 | unset -n r1 r2 37 | 38 | x=one 39 | y=two 40 | typeset -n r1=r2 41 | typeset -n r2=x 42 | typeset -n r1=y 43 | 44 | typeset -p r1 r2 x y 45 | -------------------------------------------------------------------------------- /tests/arith6.sub: -------------------------------------------------------------------------------- 1 | function reorder 2 | { 3 | (( x[1] < x && (x=x[1], x[1]=$x) )) 4 | echo "${x[@]}" 5 | } 6 | 7 | x=(123 456) 8 | reorder 9 | x=(456 123) 10 | reorder 11 | 12 | unset x 13 | unset -f reorder 14 | 15 | function reorder 16 | { 17 | (( x[1] < x[0] && (x=x[1], x[1]=$x) )) 18 | echo "${x[@]}" 19 | } 20 | 21 | x=(123 456) 22 | reorder 23 | x=(456 123) 24 | reorder 25 | 26 | unset x 27 | unset -f reorder 28 | 29 | function reorder 30 | { 31 | (( x[1] < x[0] && (x[0]=x[1], x[1]=$x) )) 32 | echo "${x[@]}" 33 | } 34 | 35 | x=(123 456) 36 | reorder 37 | x=(456 123) 38 | reorder 39 | 40 | unset -f reorder 41 | 42 | n=0 ; (( (a[n]=++n)<7&&a[0])); echo "${a[@]:1}" 43 | 44 | n=0 a="(a[n]=++n)<7&&a[0]"; ((a[0])); echo "${a[@]:1}" 45 | 46 | n=0 a="(a[n]=n++)<7&&a"; ((a)); echo "${a[@]:1}" 47 | 48 | # bugs with lvalue caching and pointer aliasing through bash-4.2 49 | echo $(( a=(y[0] + y[1]) & 0xff, b=(y[2] + y[3]) & 0xff, a << 8 | b)) 50 | echo $a, $b 51 | ((a = y[0], b = 1 )) 52 | echo $a, $b 53 | -------------------------------------------------------------------------------- /tests/posixexp2.sub: -------------------------------------------------------------------------------- 1 | 2 | x=a\ b 3 | [ "$x" = "${x?}" ] || exit 1 4 | set -- ${x?} 5 | { [ "$#" = 2 ] && [ "$1" = a ] && [ "$2" = b ]; } || exit 1 6 | unset x 7 | (echo ${x?abcdefg}) 2>&1 | grep abcdefg >/dev/null || exit 1 8 | ${THIS_SH} -c 'unset foo; echo ${foo?}' 2>/dev/null && exit 2 9 | ${THIS_SH} -c 'foo=; echo ${foo:?}' 2>/dev/null && exit 3 10 | ${THIS_SH} -c 'foo=; echo ${foo?}' >/dev/null || exit 4 11 | ${THIS_SH} -c 'foo=1; echo ${foo:?}' >/dev/null || exit 5 12 | ${THIS_SH} -c 'echo ${!?}' 2>/dev/null && exit 6 13 | ${THIS_SH} -c ':& echo ${!?}' >/dev/null || exit 7 14 | ${THIS_SH} -c 'echo ${#?}' >/dev/null || exit 8 15 | ${THIS_SH} -c 'echo ${*?}' 2>/dev/null && exit 9 16 | ${THIS_SH} -c 'echo ${*?}' ${THIS_SH} x >/dev/null || exit 10 17 | ${THIS_SH} -c 'echo ${1?}' 2>/dev/null && exit 11 18 | ${THIS_SH} -c 'echo ${1?}' ${THIS_SH} x >/dev/null || exit 12 19 | ${THIS_SH} -c 'echo ${2?}' ${THIS_SH} x 2>/dev/null && exit 13 20 | ${THIS_SH} -c 'echo ${2?}' ${THIS_SH} x y >/dev/null || exit 14 21 | exit 0 22 | -------------------------------------------------------------------------------- /tests/prec.right: -------------------------------------------------------------------------------- 1 | `Say' echos its argument. Its return value is of no interest. 2 | `Truth' echos its argument and returns a TRUE result. 3 | `False' echos its argument and returns a FALSE result. 4 | 5 | Truth 1 && Truth 2 || Say 3 output=12 6 | ( Truth 1 && Truth 2 ) || Say 3 output=12 7 | 8 | Truth 1 && False 2 || Say 3 output=123 9 | ( Truth 1 && False 2 ) || Say 3 output=123 10 | 11 | False 1 && Truth 2 || Say 3 output=13 12 | ( False 1 && Truth 2 ) || Say 3 output=13 13 | 14 | False 1 && False 2 || Say 3 output=13 15 | ( False 1 && False 2 ) || Say 3 output=13 16 | 17 | Truth 1 || Truth 2 && Say 3 output=13 18 | Truth 1 || ( Truth 2 && Say 3 ) output=1 19 | 20 | Truth 1 || False 2 && Say 3 output=13 21 | Truth 1 || ( False 2 && Say 3 ) output=1 22 | 23 | False 1 || Truth 2 && Say 3 output=123 24 | False 1 || ( Truth 2 && Say 3 ) output=123 25 | 26 | False 1 || False 2 && Say 3 output=12 27 | False 1 || ( False 2 && Say 3 ) output=12 28 | 29 | -------------------------------------------------------------------------------- /tests/arith3.sub: -------------------------------------------------------------------------------- 1 | RANDOM=42 2 | (( dice[RANDOM%6+1 + RANDOM%6+1]++ )) 3 | echo ${dice[5]} 4 | 5 | (( ++dice[RANDOM%6+1 + RANDOM%6+1] )) 6 | echo ${dice[6]} 7 | 8 | v=4 9 | DIND=20 10 | 11 | (( dice[DIND%6 + 1]=v )) 12 | echo ${dice[3]} 13 | 14 | RANDOM=42 15 | 16 | (( dice[RANDOM%6+1 + RANDOM%6+1]+=v )) 17 | echo ${dice[5]} 18 | 19 | (( dice[RANDOM%6+1 + RANDOM%6+1]-=v )) 20 | echo ${dice[6]} 21 | 22 | (( dice[RANDOM%6+1 + RANDOM%6+1]+=2 )) 23 | echo ${dice[11]} 24 | 25 | (( dice[RANDOM%6+1 + RANDOM%6+1]*=2 )) 26 | echo ${dice[11]} 27 | 28 | unset dice1 dice2 29 | RANDOM=42 30 | 31 | for i in {1..5000}; do ((dice1[$RANDOM%6+1 + $RANDOM%6+1]++)); done; 32 | unset t; for i in ${dice1[@]}; do ((t+=i)); done; echo $t 33 | 34 | foo="${dice1[@]}" 35 | 36 | RANDOM=42 37 | 38 | for i in {1..5000}; do ((dice2[RANDOM%6+1 + RANDOM%6+1]++)); done; 39 | unset t; for i in ${dice2[@]}; do ((t+=i)); done; echo $t 40 | 41 | bar="${dice2[@]}" 42 | 43 | if [ "$foo" != "$bar" ]; then 44 | echo "random sequences differ" 45 | fi 46 | -------------------------------------------------------------------------------- /tests/ifs.tests: -------------------------------------------------------------------------------- 1 | OIFS="$IFS" 2 | IFS=":$IFS" 3 | eval foo="a:b:c" 4 | IFS="$OIFS" 5 | echo $foo 6 | 7 | OIFS=$IFS 8 | IFS=":$IFS" 9 | foo=$(echo a:b:c) 10 | IFS=$OIFS 11 | 12 | for i in $foo 13 | do 14 | echo $i 15 | done 16 | 17 | OIFS=$IFS 18 | IFS=":$IFS" 19 | foo=`echo a:b:c` 20 | IFS=$OIFS 21 | 22 | for i in $foo 23 | do 24 | echo $i 25 | done 26 | 27 | DEFIFS=$' \t\n' 28 | 29 | # local copy of IFS that shadows global version 30 | function f 31 | { 32 | typeset IFS=: 33 | 34 | echo $1 35 | } 36 | 37 | function ff 38 | { 39 | echo $1 40 | } 41 | 42 | f a:b:c:d:e 43 | x=a:b:c:d:e 44 | echo $x 45 | 46 | IFS=: ff a:b:c:d:e 47 | echo $x 48 | 49 | # doesn't get word split 50 | IFS=$DEFIFS 51 | # variable assignment doesn't use new value for word splitting 52 | IFS=: echo $x 53 | # but does this time because of the eval 54 | IFS=: eval echo \$x 55 | 56 | # in posix mode, assignments preceding special builtins and functions are global 57 | set -o posix 58 | IFS=: export x 59 | echo $x 60 | 61 | IFS="$DEFIFS" 62 | -------------------------------------------------------------------------------- /tests/comsub1.sub: -------------------------------------------------------------------------------- 1 | : $(echo \;) 2 | 3 | : $(case a in a) echo ;;# comment 4 | esac) 5 | 6 | : $(case a in a) echo ;; # comment 7 | esac) 8 | 9 | : $(: \;# not a comment ) 10 | 11 | : $(: \ # not a comment) 12 | 13 | echo $(case a in a) echo \#esac ;; 14 | esac) 15 | 16 | : $(case a in a) : ;#esac ;; 17 | esac) 18 | 19 | : $(case a in a) : ;#esac comment ) 20 | esac) 21 | 22 | : $(case a in a) : ; 23 | esac) 24 | 25 | echo $(#comment ) 26 | echo a) 27 | 28 | echo $(case a in (a) echo ok 1;; # comment 29 | esac) 30 | 31 | echo $(case a in (a) echo ok 2;; # comment 32 | (b) echo moo;; 33 | esac) 34 | 35 | echo $(case a in (a) echo ok 3 # comment 36 | ;; 37 | esac) 38 | 39 | echo $(case a in a) echo ok 4;; # comment 40 | esac) 41 | 42 | echo $(case a in a) echo ok 5;; # comment 43 | b) echo moo;; 44 | esac) 45 | 46 | echo $(case a in (a) echo ok 6 # comment 47 | ;; 48 | esac) 49 | 50 | echo $( # we just took and pasted in some 51 | # code from another script inside a 52 | # command substitution 53 | echo xyz 54 | ) 55 | -------------------------------------------------------------------------------- /tests/intl.tests: -------------------------------------------------------------------------------- 1 | export LC_ALL=en_US.UTF-8 2 | 3 | a=$'\303\251' 4 | 5 | echo "$a" 6 | 7 | echo ${#a} 8 | 9 | b=$'A\303\251B' 10 | 11 | echo "$b" 12 | 13 | echo ${b: -1} 14 | 15 | c=AeB 16 | 17 | echo ${c: -1} 18 | 19 | unset a 20 | a=$(printf '%b' 'A\303\251B') 21 | IFS=$(printf '%b' '\303\251') 22 | 23 | case "$a" in 24 | "A${IFS}B") echo ok 1 ;; 25 | *) echo bad 1 ;; 26 | esac 27 | 28 | set $a 29 | 30 | case $1 in 31 | A) echo ok 2 ;; 32 | *) echo bad 2 ;; 33 | esac 34 | 35 | set a b 36 | 37 | printf '%s\n' "$*" 38 | 39 | . ./test-glue-functions 40 | 41 | printf '%s' "$*" | od -b | _intl_normalize_spaces 42 | 43 | # display differences make this problematic 44 | ${THIS_SH} ./intl1.sub 45 | 46 | # this tests both international handling in printf and temporary environments 47 | ${THIS_SH} ./intl2.sub 48 | 49 | # test splitting on characters instead of bytes 50 | ${THIS_SH} ./intl3.sub 51 | 52 | ${THIS_SH} ./unicode1.sub 2>/dev/null 53 | ${THIS_SH} ./unicode2.sub 54 | 55 | ${THIS_SH} ./unicode3.sub 2>&1 56 | -------------------------------------------------------------------------------- /lib/sh/fmtumax.c: -------------------------------------------------------------------------------- 1 | /* fmtumax.c -- Convert uintmax_t to string. */ 2 | 3 | /* Copyright (C) 2002 Free Software Foundation, Inc. 4 | 5 | This file is part of GNU Bash, the Bourne Again SHell. 6 | 7 | Bash is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | Bash is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with Bash. If not, see . 19 | */ 20 | 21 | #include 22 | 23 | #define LONG intmax_t 24 | #define UNSIGNED_LONG uintmax_t 25 | #define fmtulong fmtumax 26 | 27 | #include "fmtulong.c" 28 | --------------------------------------------------------------------------------