├── ChangeLog ├── tests ├── redir4.in1 ├── exec1.sub ├── redir3.in1 ├── source1.sub ├── source3.sub ├── redir3.in2 ├── source4.sub ├── comsub-eof2.sub ├── exec8.sub ├── redir2.sub ├── array1.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 ├── intl.right ├── posix2.right ├── read4.sub ├── array.right ├── README ├── nquote4.right ├── set-e3a.sub ├── invert.right ├── array2.sub ├── redir6.sub ├── trap2a.sub ├── run-braces ├── run-case ├── run-ifs ├── run-precedence ├── run-rsh ├── run-set-e ├── run-strip ├── run-tilde ├── run-tilde2 ├── run-type ├── run-alias ├── run-arith ├── run-comsub ├── run-cprint ├── run-errors ├── run-iquote ├── run-quote ├── run-shopt ├── run-vredir ├── errors2.sub ├── exec4.sub ├── run-casemod ├── run-dollars ├── run-getopts ├── run-herestr ├── run-input-test ├── run-mapfile ├── run-posixpat ├── run-rhs-exp ├── comsub-eof5.sub ├── run-appendop ├── run-arith-for ├── run-ifs-posix ├── run-lastpipe ├── run-posixexp ├── run-posixexp2 ├── run-posixpipe ├── exec3.sub ├── run-comsub-eof ├── run-exp-tests ├── run-varenv ├── heredoc2.sub ├── history.list ├── run-comsub-posix ├── run-invert ├── run-nquote ├── run-posix2 ├── source2.sub ├── nquote1.sub ├── run-nquote5 ├── trap1.sub ├── run-more-exp ├── exec2.sub ├── run-test ├── dollar-at3.sub ├── dollar-star4.sub ├── run-extglob3 ├── input.right ├── run-globstar ├── ifs.right ├── type1.sub ├── arith4.sub ├── input-line.sh ├── run-extglob ├── trap3.sub ├── dbg-support2.right ├── lastpipe1.sub ├── run-extglob2 ├── run-glob-test ├── array3.sub ├── dollar-at4.sub ├── unicode3.sub ├── vredir3.sub ├── nameref2.sub ├── alias.right ├── strip.right ├── redir1.sub ├── vredir1.sub ├── exp4.sub ├── type2.sub ├── heredoc1.sub ├── lastpipe.right ├── version ├── run-dirstack ├── printf2.sub ├── version.mini ├── builtins2.sub ├── dollar-star5.sub ├── exp3.sub ├── jobs5.sub ├── run-coproc ├── coproc.right ├── history2.sub ├── run-assoc ├── new-exp7.sub ├── run-array2 ├── run-history ├── run-nameref ├── builtins1.sub ├── builtins3.sub ├── dollar-at2.sub ├── run-histexpand ├── run-read ├── intl1.sub ├── history1.sub ├── comsub-eof.tests ├── vredir6.sub ├── nameref7.sub ├── run-nquote1 ├── run-nquote2 ├── run-nquote3 ├── run-nquote4 ├── new-exp1.sub ├── comsub-posix3.sub ├── intl2.sub ├── read6.sub ├── set-e3.sub ├── glob1.sub ├── type3.sub ├── errors3.sub ├── nameref1.sub ├── assoc3.sub ├── jobs2.sub ├── appendop1.sub ├── case.right ├── errors1.sub ├── exec5.sub ├── vredir4.sub ├── dollar-star2.sub ├── mapfile1.sub ├── run-func ├── varenv5.sub ├── array13.sub ├── run-builtins ├── assoc1.sub ├── vredir5.sub ├── dollar-star6.sub ├── jobs1.sub ├── run-trap ├── appendop2.sub ├── exp2.sub ├── extglob1a.sub ├── run-heredoc ├── assoc7.sub ├── exec9.sub ├── run-jobs ├── run-printf ├── assoc2.sub ├── read1.sub ├── dollar-star3.sub ├── globstar1.sub ├── redir3.sub ├── run-array ├── array7.sub ├── extglob3.right ├── run-set-x ├── run-cond ├── run-dbg-support ├── trap2.sub ├── alias1.sub ├── source5.sub ├── set-x.tests ├── array9.sub ├── new-exp3.sub ├── COPYRIGHT ├── func2.sub ├── set-x1.sub ├── tilde2.right ├── assoc4.sub ├── exp5.sub ├── read3.sub ├── array8.sub ├── mapfile.data ├── redir10.sub ├── dollar-at-star1.sub ├── run-intl ├── varenv6.sub ├── dollar-at1.sub ├── dstack2.right ├── redir5.sub ├── nquote4.tests ├── posixpat.right ├── posixpipe.right ├── run-redir ├── strip.tests ├── tilde.right ├── array15.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 ├── array12.sub ├── array5.sub ├── type4.sub ├── herestr.right ├── getopts6.sub ├── exec7.sub ├── new-exp6.sub ├── read5.sub ├── varenv2.sub ├── dbg-support2.tests ├── herestr.tests ├── set-e2.sub ├── array16.sub ├── array4.sub ├── unicode2.sub ├── func4.sub ├── posixpipe.tests ├── getopts2.sub ├── varenv4.sub ├── getopts3.sub ├── arith1.sub ├── run-new-exp ├── appendop.right ├── redir9.sub ├── comsub.right ├── source6.sub ├── run-execscript ├── new-exp9.sub ├── run-all ├── case.tests ├── dbg-support3.sub ├── getopts4.sub ├── getopts7.sub ├── vredir.tests ├── array11.sub ├── builtins4.sub ├── dstack2.tests ├── arith2.sub ├── nquote2.sub ├── rsh.tests ├── vredir2.sub ├── extglob1.sub ├── rsh.right ├── comsub-eof.right ├── new-exp5.sub ├── posixexp2.right ├── alias.tests ├── dbg-support.sub ├── nameref8.sub ├── coproc.tests ├── nameref6.sub ├── set-x.right ├── dollar-star7.sub ├── exp6.sub ├── comsub.tests ├── nameref3.sub ├── getopts5.sub ├── comsub1.sub ├── cond-regexp2.sub ├── func3.sub ├── func1.sub ├── source7.sub ├── set-e.right ├── redir8.sub ├── iquote1.sub ├── redir4.sub ├── new-exp4.sub ├── arith6.sub ├── posixexp2.sub ├── prec.right ├── intl.tests ├── arith3.sub ├── ifs.tests ├── read.right ├── case1.sub ├── mapfile.tests ├── nquote.right ├── new-exp2.sub ├── tilde2.tests ├── redir7.sub ├── run-minimal ├── globstar2.sub ├── posixexp.right ├── nameref5.sub ├── exec6.sub └── exec.right ├── lib ├── glob │ └── doc │ │ ├── glob.texi │ │ └── Makefile ├── intl │ ├── VERSION │ ├── locale.alias │ ├── ChangeLog │ ├── osdep.c │ ├── ref-del.sin │ └── ref-add.sin ├── tilde │ └── README ├── malloc │ ├── i386-alloca.s │ ├── stub.c │ └── xleaktrace ├── sh │ ├── fmtumax.c │ ├── memset.c │ ├── strtoul.c │ ├── fmtullong.c │ ├── strtoll.c │ └── strtoull.c └── termcap │ ├── version.c │ └── ltcap.h ├── po ├── README ├── af.po ├── ca.po ├── et.po ├── ro.po ├── ru.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 ├── nl.gmo ├── pl.gmo ├── pt_BR.po ├── 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 ├── 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 │ └── csh-compat ├── complete │ └── bashcc-1.0.1.tar.gz ├── scripts │ ├── cat.sh │ └── inpath ├── loadables │ └── perl │ │ ├── README │ │ ├── iperl.c │ │ └── bperl.c ├── startup-files │ ├── Bash_profile │ ├── README │ └── bash-profile └── misc │ ├── aliasconv.sh │ └── aliasconv.bash ├── .gitmodules ├── Y2K ├── MANIFEST.doc ├── support ├── SYMLINKS └── printenv.sh └── .gitignore /ChangeLog: -------------------------------------------------------------------------------- 1 | CWRU/changelog -------------------------------------------------------------------------------- /tests/redir4.in1: -------------------------------------------------------------------------------- 1 | aa 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 | -------------------------------------------------------------------------------- /tests/run-braces: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./braces.tests > /tmp/xx 2 | diff /tmp/xx braces.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-case: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./case.tests > /tmp/xx 2>&1 2 | diff /tmp/xx case.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-ifs: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./ifs.tests > /tmp/xx 2>&1 2 | diff /tmp/xx ifs.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-precedence: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./precedence > /tmp/xx 2 | diff /tmp/xx prec.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-rsh: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./rsh.tests > /tmp/xx 2>&1 2 | diff /tmp/xx rsh.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-set-e: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./set-e.tests > /tmp/xx 2 | diff /tmp/xx set-e.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-strip: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./strip.tests > /tmp/xx 2 | diff /tmp/xx strip.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-tilde: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./tilde.tests > /tmp/xx 2 | diff /tmp/xx tilde.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-tilde2: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./tilde2.tests > /tmp/xx 2 | diff /tmp/xx tilde2.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-type: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./type.tests > /tmp/xx 2>&1 2 | diff /tmp/xx type.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /lib/intl/ChangeLog: -------------------------------------------------------------------------------- 1 | 2003-05-22 GNU 2 | 3 | * Version 0.12.1 released. 4 | 5 | -------------------------------------------------------------------------------- /tests/run-alias: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./alias.tests > /tmp/xx 2>&1 2 | diff /tmp/xx alias.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-arith: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./arith.tests > /tmp/xx 2>&1 2 | diff /tmp/xx arith.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-comsub: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./comsub.tests > /tmp/xx 2>&1 2 | diff /tmp/xx comsub.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-cprint: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./cprint.tests > /tmp/xx 2>&1 2 | diff /tmp/xx cprint.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-errors: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./errors.tests > /tmp/xx 2>&1 2 | diff /tmp/xx errors.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-iquote: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./iquote.tests >/tmp/xx 2>&1 2 | diff /tmp/xx iquote.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-quote: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./quote.tests >/tmp/xx 2>&1 2 | diff /tmp/xx quote.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-shopt: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./shopt.tests > /tmp/xx 2>&1 2 | diff /tmp/xx shopt.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-vredir: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./vredir.tests > /tmp/xx 2>&1 2 | diff /tmp/xx vredir.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /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/run-casemod: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./casemod.tests > /tmp/xx 2>&1 2 | diff /tmp/xx casemod.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-dollars: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./dollar-at-star > /tmp/xx 2>&1 2 | diff /tmp/xx dollar.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-getopts: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./getopts.tests > /tmp/xx 2>&1 2 | diff /tmp/xx getopts.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-herestr: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./herestr.tests > /tmp/xx 2>&1 2 | diff /tmp/xx herestr.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-input-test: -------------------------------------------------------------------------------- 1 | ${THIS_SH} < ./input-line.sh > /tmp/xx 2 | diff /tmp/xx input.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-mapfile: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./mapfile.tests > /tmp/xx 2>&1 2 | diff /tmp/xx mapfile.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-posixpat: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./posixpat.tests > /tmp/xx 2 | diff /tmp/xx posixpat.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-rhs-exp: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./rhs-exp.tests 2>&1 > /tmp/xx 2 | diff /tmp/xx rhs-exp.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/comsub-eof5.sub: -------------------------------------------------------------------------------- 1 | echo $( 2 | cat <<\) 3 | hi 4 | )) 5 | 6 | echo $( 7 | cat <<\EOF 8 | hi 9 | EOF) 10 | -------------------------------------------------------------------------------- /tests/run-appendop: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./appendop.tests > /tmp/xx 2>&1 2 | diff /tmp/xx appendop.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-arith-for: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./arith-for.tests > /tmp/xx 2>&1 2 | diff /tmp/xx arith-for.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-ifs-posix: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./ifs-posix.tests > /tmp/xx 2>&1 2 | diff /tmp/xx ifs-posix.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-lastpipe: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./lastpipe.tests > /tmp/xx 2>&1 2 | diff /tmp/xx lastpipe.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-posixexp: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./posixexp.tests > /tmp/xx 2>&1 2 | diff /tmp/xx posixexp.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-posixexp2: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./posixexp2.tests > /tmp/xx 2>&1 2 | diff /tmp/xx posixexp2.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-posixpipe: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./posixpipe.tests > /tmp/xx 2>&1 2 | diff /tmp/xx posixpipe.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /examples/complete/bashcc-1.0.1.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/calid/bash/HEAD/examples/complete/bashcc-1.0.1.tar.gz -------------------------------------------------------------------------------- /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-comsub-eof: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./comsub-eof.tests > /tmp/xx 2>&1 2 | diff /tmp/xx comsub-eof.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-exp-tests: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./exp.tests | grep -v '^expect' > /tmp/xx 2 | diff /tmp/xx exp.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-varenv: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./varenv.sh | grep -v '^expect' > /tmp/xx 2 | diff /tmp/xx varenv.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/heredoc2.sub: -------------------------------------------------------------------------------- 1 | TEST=$(cat < /tmp/xx 2>&1 2 | diff /tmp/xx comsub-posix.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-invert: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./invert.tests 2>&1 | grep -v '^expect' > /tmp/xx 2 | diff /tmp/xx invert.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-nquote: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./nquote.tests 2>&1 | grep -v '^expect' > /tmp/xx 2 | diff /tmp/xx nquote.right && rm -f /tmp/xx 3 | -------------------------------------------------------------------------------- /tests/run-posix2: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./posix2.tests 2>&1 | grep -v '^expect' > /tmp/xx 2 | diff /tmp/xx posix2.right && rm -f /tmp/xx 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-nquote5: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./nquote5.tests 2>&1 | grep -v '^expect' > /tmp/xx 2 | diff /tmp/xx nquote5.right && rm -f /tmp/xx 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/run-more-exp: -------------------------------------------------------------------------------- 1 | ${THIS_SH} ./more-exp.tests 2>&1 | grep -v '^expect' > /tmp/xx 2 | diff /tmp/xx more-exp.right && rm -f /tmp/xx 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-test: -------------------------------------------------------------------------------- 1 | unset GROUPS UID 2>/dev/null 2 | 3 | ${THIS_SH} ./test.tests >/tmp/xx 2>&1 4 | diff /tmp/xx test.right && rm -f /tmp/xx 5 | -------------------------------------------------------------------------------- /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-extglob3: -------------------------------------------------------------------------------- 1 | PATH=$PATH:`pwd` 2 | export PATH 3 | ${THIS_SH} ./extglob3.tests > /tmp/xx 4 | diff /tmp/xx extglob3.right && rm -f /tmp/xx 5 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "readline"] 2 | path = lib/readline 3 | url = https://github.com/calid/readline.git 4 | branch = modestrs-bash-embedded 5 | -------------------------------------------------------------------------------- /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/run-globstar: -------------------------------------------------------------------------------- 1 | PATH=$PATH:`pwd` 2 | export PATH 3 | ${THIS_SH} ./globstar.tests > /tmp/xx 2>&1 4 | diff /tmp/xx globstar.right && rm -f /tmp/xx 5 | -------------------------------------------------------------------------------- /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/type1.sub: -------------------------------------------------------------------------------- 1 | foo() 2 | { 3 | echo $( /tmp/xx 4 | diff /tmp/xx extglob.right && rm -f /tmp/xx 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-extglob2: -------------------------------------------------------------------------------- 1 | PATH=$PATH:`pwd` 2 | export PATH 3 | ${THIS_SH} ./extglob2.tests | grep -v '^expect' > /tmp/xx 4 | diff /tmp/xx extglob2.right && rm -f /tmp/xx 5 | -------------------------------------------------------------------------------- /tests/run-glob-test: -------------------------------------------------------------------------------- 1 | PATH=$PATH:`pwd` 2 | export PATH 3 | ${THIS_SH} ./glob.tests 2>&1 | grep -v '^expect' > /tmp/xx 4 | diff /tmp/xx glob.right && rm -f /tmp/xx 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/unicode3.sub: -------------------------------------------------------------------------------- 1 | payload=$'\065\247\100\063\231\053\306\123\070\237\242\352\263' 2 | "$payload" 3 | 4 | printf %q "$payload" 5 | echo 6 | 7 | set -x ; : "$payload" 8 | -------------------------------------------------------------------------------- /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 nl pl pt_BR ro ru sk sl sr sv tr uk vi zh_CN zh_TW 3 | -------------------------------------------------------------------------------- /tests/alias.right: -------------------------------------------------------------------------------- 1 | alias: 0 2 | alias: 0 3 | ./alias.tests: line 25: qfoo: command not found 4 | quux 5 | bar 6 | value 7 | bar 8 | value 9 | OK 10 | OK 11 | OK 12 | OK 13 | -------------------------------------------------------------------------------- /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/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}< /tmp/xx 2>&1 2 | diff /tmp/xx dstack.right && rm -f /tmp/xx 3 | 4 | ${THIS_SH} ./dstack2.tests > /tmp/xx 2>&1 5 | diff /tmp/xx dstack2.right && rm -f /tmp/xx 6 | -------------------------------------------------------------------------------- /tests/printf2.sub: -------------------------------------------------------------------------------- 1 | unset LC_ALL LC_CTYPE 2 | export LANG=en_US.UTF-8 3 | 4 | case $(printf %d\\n \'À) in 5 | 192) exit 0;; 6 | *) echo "printf2.sub: multibyte character conversion failed" >&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/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/run-coproc: -------------------------------------------------------------------------------- 1 | echo "warning: the process IDs printed will differ on every run" >&2 2 | echo "warning: and generate diffs" >&2 3 | ${THIS_SH} ./coproc.tests > /tmp/xx 2>&1 4 | diff /tmp/xx coproc.right && rm -f /tmp/xx 5 | -------------------------------------------------------------------------------- /tests/coproc.right: -------------------------------------------------------------------------------- 1 | 84575 2 | 63 60 3 | a b c 4 | 84577 5 | 63 60 6 | flop 7 | ./coproc.tests: line 22: 84577 Terminated coproc REFLECT { cat -; } 8 | 84579 9 | 63 60 10 | FOO 11 | 63 60 12 | root 13 | -1 -1 14 | -------------------------------------------------------------------------------- /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/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 > /tmp/xx 2>&1 4 | diff /tmp/xx assoc.right && rm -f /tmp/xx 5 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/run-array2: -------------------------------------------------------------------------------- 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} ./array-at-star > /tmp/xx 2>&1 4 | diff /tmp/xx array2.right && rm -f /tmp/xx 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 > /tmp/xx 2>&1 4 | diff /tmp/xx history.right && rm -f /tmp/xx 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 > /tmp/xx 2>&1 4 | diff /tmp/xx nameref.right && rm -f /tmp/xx 5 | -------------------------------------------------------------------------------- /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/run-histexpand: -------------------------------------------------------------------------------- 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} ./histexp.tests > /tmp/xx 2>&1 4 | diff /tmp/xx histexp.right && rm -f /tmp/xx 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 > /tmp/xx 2>&1 4 | diff /tmp/xx read.right && rm -f /tmp/xx 5 | -------------------------------------------------------------------------------- /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/history1.sub: -------------------------------------------------------------------------------- 1 | trap 'rm -f $HISTFILE' 0 1 2 3 6 15 2 | 3 | HISTFILE=foohist-$$ 4 | unset HISTIGNORE HISTCONTROL 5 | set -o history 6 | 7 | history -c 8 | cat <= 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: been compiled into the shell." >&2 3 | ${THIS_SH} ./nquote1.tests 2>&1 | grep -v '^expect' > /tmp/xx 4 | diff /tmp/xx nquote1.right && rm -f /tmp/xx 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' > /tmp/xx 4 | diff /tmp/xx nquote2.right && rm -f /tmp/xx 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' > /tmp/xx 4 | diff /tmp/xx nquote3.right && rm -f /tmp/xx 5 | -------------------------------------------------------------------------------- /tests/run-nquote4: -------------------------------------------------------------------------------- 1 | echo warning: some of these tests will fail if you do not have UTF-8 >&2 2 | echo warning: locales installed on your system >&2 3 | ${THIS_SH} ./nquote4.tests 2>&1 | grep -v '^expect' > /tmp/xx 4 | diff /tmp/xx nquote4.right && rm -f /tmp/xx 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/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 | -------------------------------------------------------------------------------- /doc/version.texi: -------------------------------------------------------------------------------- 1 | @ignore 2 | Copyright (C) 1988-2014 Free Software Foundation, Inc. 3 | @end ignore 4 | 5 | @set LASTCHANGE Sun Feb 2 16:22:00 EST 2014 6 | 7 | @set EDITION 4.3 8 | @set VERSION 4.3 9 | @set UPDATED 2 February 2014 10 | @set UPDATED-MONTH February 2014 11 | -------------------------------------------------------------------------------- /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/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/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 | ok 1 11 | ok 2 12 | ok 3 13 | ok 4 14 | ok 5 15 | ok 6 16 | ok 7 17 | ok 8 18 | ok 9 19 | mysterious 1 20 | mysterious 2 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/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/run-func: -------------------------------------------------------------------------------- 1 | echo "warning: if you have exported functions defined in your environment," >&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 > /tmp/xx 2>&1 5 | diff /tmp/xx func.right && rm -f /tmp/xx 6 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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 > /tmp/xx 2>&1 6 | diff /tmp/xx builtins.right && rm -f /tmp/xx 7 | -------------------------------------------------------------------------------- /tests/assoc1.sub: -------------------------------------------------------------------------------- 1 | hash -r 2 | echo ${BASH_CMDS[@]} 3 | 4 | hash -p /usr/sbin/foo foo 5 | hash -p /usr/local/bin/qux qux 6 | 7 | echo ${!BASH_CMDS[@]} 8 | echo ${BASH_CMDS[@]} 9 | 10 | BASH_CMDS[blat]=/sbin/blat 11 | BASH_CMDS[sh]=/bin/sh 12 | 13 | hash 14 | 15 | echo ${!BASH_CMDS[@]} 16 | echo "${BASH_CMDS[@]}" 17 | -------------------------------------------------------------------------------- /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-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 > /tmp/xx 2>&1 6 | diff /tmp/xx trap.right && rm -f /tmp/xx 7 | -------------------------------------------------------------------------------- /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/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 > /tmp/xx 2>&1 6 | diff /tmp/xx heredoc.right && rm -f /tmp/xx 7 | -------------------------------------------------------------------------------- /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/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/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 > /tmp/xx 2>&1 7 | diff /tmp/xx jobs.right && rm -f /tmp/xx 8 | -------------------------------------------------------------------------------- /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 > /tmp/xx 6 | #diff $AFLAG /tmp/xx printf.right && rm -f /tmp/xx 7 | diff /tmp/xx printf.right && rm -f /tmp/xx 8 | -------------------------------------------------------------------------------- /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/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/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 > /tmp/xx 2>&1 6 | diff /tmp/xx array.right && rm -f /tmp/xx 7 | -------------------------------------------------------------------------------- /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-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/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 > /tmp/xx 2>&1 7 | diff /tmp/xx cond.right && rm -f /tmp/xx 8 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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/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/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 | 12 | IFS="-$IFS" 13 | 14 | recho ${!_Q*} 15 | recho "${!_Q*}" 16 | 17 | recho ${!_Y*} 18 | 19 | recho "${!_Q* }" 20 | 21 | IFS=$' \t\n' 22 | 23 | set a b c d e f g h i j k l m n o p 24 | recho ${!1*} 25 | 26 | recho ${!@*} 27 | -------------------------------------------------------------------------------- /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/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/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 | echo "warning: please ignore any differences consisting only of white space" >&2 7 | ${THIS_SH} ./intl.tests > /tmp/xx 8 | diff $AFLAG /tmp/xx intl.right && rm -f /tmp/xx 9 | -------------------------------------------------------------------------------- /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/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/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 > /tmp/xx 2>&1 7 | diff /tmp/xx redir.right && rm -f /tmp/xx 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-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/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/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/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 | -------------------------------------------------------------------------------- /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/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/unicode2.sub: -------------------------------------------------------------------------------- 1 | export LANG=en_US.UTF-8 2 | 3 | printf '%s\n' "$(printf '\uff')" | od -b 4 | printf '%s\n' $'\uff' | od -b 5 | 6 | printf '\uff'\\n | od -b 7 | echo $'\uff' | od -b 8 | 9 | printf '\uffff'\\n | od -b 10 | echo $'\uffff' | od -b 11 | 12 | printf '\Ufffffffe'\\n | od -b 13 | echo $'\Ufffffffe' | od -b 14 | 15 | printf '\Uffffffff'\\n | od -b 16 | echo $'\Uffffffff' | od -b 17 | 18 | LC_CTYPE=C printf '\uff'\\n | od -b 19 | LC_CTYPE=ru_RU.CP1251 printf '\uff'\\n | od -b 20 | LC_CTYPE=en_US.UTF-8 printf '\uff'\\n | od -b 21 | 22 | echo -e '\u0041 \u00a3 \u0152' | od -b 23 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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' > /tmp/xx 10 | diff /tmp/xx new-exp.right && rm -f /tmp/xx 11 | -------------------------------------------------------------------------------- /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/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='([one]="bar" [two]="baz" [three]="quux" )' 20 | declare -A foo='([one]="bar" [two]="baz" [0]="zero" [three]="quux" )' 21 | declare -A foo='([four]="four" [one]="bar" [two]="baz" [0]="zero" [three]="quux" )' 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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | echo "echo three - OK" | . /dev/stdin 23 | echo $? 24 | 25 | # FIFO 26 | mkfifo $TMPDIR/fifo-$$ 27 | echo "echo four - OK" > $TMPDIR/fifo-$$ & 28 | sleep 1 # allow the child echo to execute 29 | . $TMPDIR/fifo-$$ 30 | echo $? 31 | rm -f $TMPDIR/fifo-$$ 32 | -------------------------------------------------------------------------------- /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 > /tmp/xx 2>&1 9 | diff /tmp/xx exec.right && rm -f /tmp/xx 10 | -------------------------------------------------------------------------------- /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/run-all: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | PATH=.:$PATH # just to get recho/zecho/printenv if not run via `make tests' 4 | export PATH 5 | 6 | # unset BASH_ENV only if it is set 7 | [ "${BASH_ENV+set}" = "set" ] && unset BASH_ENV 8 | # ditto for SHELLOPTS 9 | #[ "${SHELLOPTS+set}" = "set" ] && unset SHELLOPTS 10 | 11 | : ${THIS_SH:=../bash} 12 | export THIS_SH 13 | 14 | ${THIS_SH} ./version 15 | 16 | rm -f /tmp/xx 17 | 18 | echo Any output from any test, unless otherwise noted, indicates a possible anomaly 19 | 20 | for x in run-* 21 | do 22 | case $x in 23 | $0|run-minimal|run-gprof) ;; 24 | *.orig|*~) ;; 25 | *) echo $x ; sh $x ;; 26 | esac 27 | done 28 | 29 | exit 0 30 | -------------------------------------------------------------------------------- /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/case.tests: -------------------------------------------------------------------------------- 1 | case foo in 2 | bar) echo skip ;; 3 | foo) echo fallthrough ;& 4 | bax) echo to here ;& 5 | qux) echo and here;; 6 | fop) echo but not here;; 7 | esac 8 | 9 | case foobar in 10 | bar) echo skip ;; 11 | foo*) echo retest ;;& 12 | *bar) echo and match ;;& 13 | qux) echo but not this ;; 14 | esac 15 | 16 | case a in 17 | a) echo no more clauses;& 18 | esac 19 | 20 | x=0 y=1 21 | case 1 in 22 | $((y=0)) ) ;; 23 | $((x=1)) ) ;& 24 | $((x=2)) ) echo $x.$y ;; 25 | esac 26 | 27 | unset x 28 | readonly xx=1 29 | case 1 in $((xx++)) ) echo hi1 ;; *) echo hi2; esac 30 | echo ${xx}.$? 31 | 32 | # tests of quote removal and pattern matching 33 | ${THIS_SH} ./case1.sub 34 | -------------------------------------------------------------------------------- /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/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 | exit 0 47 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/coproc.tests: -------------------------------------------------------------------------------- 1 | coproc { echo a b c; sleep 2; } 2 | 3 | echo $COPROC_PID 4 | echo ${COPROC[@]} 5 | 6 | read LINE <&${COPROC[0]} 7 | echo $LINE 8 | 9 | wait $COPROC_PID 10 | 11 | coproc REFLECT { cat - ; } 12 | 13 | echo $REFLECT_PID 14 | echo ${REFLECT[@]} 15 | 16 | echo flop >&${REFLECT[1]} 17 | read LINE <&${REFLECT[0]} 18 | 19 | echo $LINE 20 | 21 | kill $REFLECT_PID 22 | wait $REFLECT_PID 23 | 24 | coproc xcase -n -u 25 | 26 | echo $COPROC_PID 27 | echo ${COPROC[@]} 28 | 29 | echo foo >&${COPROC[1]} 30 | read <&${COPROC[0]} 31 | 32 | echo $REPLY 33 | echo ${COPROC[@]} 34 | 35 | cat /etc/passwd | grep root | awk -F: '{print $1;}' | sed 1q 36 | 37 | exec 4<&${COPROC[0]}- 38 | exec >&${COPROC[1]}- 39 | 40 | echo ${COPROC[@]} 41 | 42 | read foo <&4 43 | echo $foo >&2 44 | 45 | exit 0 46 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /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/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/comsub.tests: -------------------------------------------------------------------------------- 1 | # command substution parsing tests 2 | 3 | TABSIZE=`grep -v '^[ #]' $CAPS " 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/getopts5.sub: -------------------------------------------------------------------------------- 1 | #!/local/bin/bash 2 | #Time-stamp: <95/06/07 07:40:40 hrue@imf.unit.no> 3 | 4 | getop () { 5 | 6 | local OPTIND 7 | local OPTERR=1 8 | 9 | echo getop: OPTERR=$OPTERR 10 | while getopts ab arg "$@"; do 11 | case $arg in 12 | a) 13 | echo a here 14 | ;; 15 | b) 16 | echo b here 17 | ;; 18 | :|?|*) 19 | echo something else here 20 | ;; 21 | esac 22 | done 23 | echo getop: OPTIND=$OPTIND 24 | } 25 | 26 | OPTIND= 27 | OPTERR=0 28 | 29 | echo OPTERR=$OPTERR 30 | while getopts ab arg; do 31 | case $arg in 32 | a) 33 | echo a here 34 | ;; 35 | b) 36 | echo b here 37 | ;; 38 | :|?|*) 39 | 40 | echo something else here 41 | ;; 42 | esac 43 | done 44 | 45 | echo OPTIND=$OPTIND 46 | 47 | getop "$@" -d -e 48 | 49 | echo OPTIND=$OPTIND 50 | echo OPTERR=$OPTERR 51 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/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/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/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 | -------------------------------------------------------------------------------- /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/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/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/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 | # squeeze out blanks to avoid white space differences in od implementations 39 | printf '%s' "$*" | od -b | ( IFS=$' \t\n' ; while read line; do echo $line; done; ) 40 | 41 | # display differences make this problematic 42 | ${THIS_SH} ./intl1.sub 43 | 44 | # this tests both international handling in printf and temporary environments 45 | ${THIS_SH} ./intl2.sub 46 | 47 | ${THIS_SH} ./unicode1.sub 2>/dev/null 48 | ${THIS_SH} ./unicode2.sub 49 | 50 | ${THIS_SH} ./unicode3.sub 2>&1 51 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /tests/read.right: -------------------------------------------------------------------------------- 1 | a. 2 | -a-b- 3 | -a-b - 4 | -a b- 5 | -a b- 6 | -a-b\- 7 | -a b\- 8 | -\-a b\- 9 | -\ a b\- 10 | -\-a b\- 11 | -\ a b\- 12 | argv[1] = <^A> 13 | argv[1] = <^A> 14 | argv[1] = <^?> 15 | argv[1] = <^?> 16 | argv[1] = 17 | 1: x[A] y[B] z[] 18 | 1a: 19 | 2: x[A B] 20 | [A B ] 21 | [ A B ] 22 | ==aa== 23 | ==== 24 | ==== 25 | argv[1] = < foo> 26 | argv[1] = < foo> 27 | argv[1] = 28 | argv[1] = < foo> 29 | argv[1] = 30 | argv[1] = 31 | argv[1] = < foo> 32 | a = abcdefg 33 | a = xyz 34 | a = -xyz 123- 35 | a = abc 36 | timeout 1: ok 37 | 38 | timeout 2: ok 39 | 40 | ./read2.sub: line 23: read: -3: invalid timeout specification 41 | 1 42 | 43 | abcde 44 | ./read3.sub: line 4: read: -1: invalid number 45 | abc 46 | ab 47 | abc 48 | # 49 | while read -u 3 var 50 | do 51 | echo "$var" 52 | done 3<$0 53 | argv[1] = <> 54 | argv[1] = <> 55 | argv[1] = <> 56 | FOO 57 | argv[1] = <> 58 | argv[1] = <3> 59 | argv[1] = <> 60 | argv[2] = <> 61 | argv[3] = <> 62 | FOO 63 | 0 0 0 64 | 0 65 | 0 66 | 1 67 | -------------------------------------------------------------------------------- /lib/termcap/version.c: -------------------------------------------------------------------------------- 1 | /* version.c - termcap library version information. */ 2 | 3 | /* Copyright (C) 1985-2009 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 | /* Make the library identifiable with the RCS ident command. */ 22 | static char *termcap_version_string = "\n$Version: GNU termcap 1.3 $\n"; 23 | -------------------------------------------------------------------------------- /tests/case1.sub: -------------------------------------------------------------------------------- 1 | x='\x' 2 | 3 | case x in 4 | \x) echo ok 1;; 5 | *) echo bad 1;; 6 | esac 7 | 8 | case x in 9 | $x) echo ok 2;; 10 | *) echo bad 2;; 11 | esac 12 | 13 | case $x in 14 | \x) echo bad 3;; 15 | \\x) echo ok 3 ;; 16 | *) echo bad 3.1 ;; 17 | esac 18 | 19 | case $x in 20 | \\$x) echo ok 4 ;; 21 | x) echo bad 4;; 22 | $x) echo bad 4.1 ;; 23 | *) echo bad 4.2;; 24 | esac 25 | 26 | case x in 27 | \\x) echo bad 5;; 28 | \x) echo ok 5;; 29 | *) echo bad 5.1;; 30 | esac 31 | 32 | case x in 33 | \\x) echo bad 6;; 34 | x) echo ok 6;; 35 | *) echo bad 6.1;; 36 | esac 37 | 38 | case x in 39 | $x) echo ok 7 ;; 40 | \\$x) echo bad 7 ;; 41 | *) echo bad 7.1 ;; 42 | esac 43 | 44 | case x in 45 | \x) echo ok 8 ;; 46 | \\x) echo bad 8 ;; 47 | *) echo bad 8.1 ;; 48 | esac 49 | 50 | case \x in 51 | \x) echo ok 9 ;; 52 | \\x) echo bad 9 ;; 53 | *) echo bad 9.1 ;; 54 | esac 55 | 56 | case $x in 57 | $x) echo oops 1 ;; 58 | *) echo mysterious 1 ;; 59 | esac 60 | 61 | case \x in 62 | \x) echo mysterious 2 ;; 63 | *) echo oops 2 ;; 64 | esac 65 | -------------------------------------------------------------------------------- /lib/sh/memset.c: -------------------------------------------------------------------------------- 1 | /* memset.c -- set an area of memory to a given value */ 2 | 3 | /* Copyright (C) 1991-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 | char * 22 | memset (char *str, int c, unsigned int len) 23 | { 24 | register char *st = str; 25 | 26 | while (len-- > 0) 27 | *st++ = c; 28 | return str; 29 | } 30 | -------------------------------------------------------------------------------- /tests/mapfile.tests: -------------------------------------------------------------------------------- 1 | declare -a A 2 | mapfile A < mapfile.data 3 | for (( i = 0 ; i < ${#A[@]} ; i++ )); do 4 | echo -n "${A[${i}]}" 5 | done 6 | 7 | declare -a B 8 | mapfile -t B < mapfile.data 9 | for (( i = 0 ; i < ${#B[@]} ; i++ )); do 10 | echo "${B[${i}]}" 11 | done 12 | 13 | mapfile -C "echo" -c 1 A < mapfile.data 14 | mapfile -C "echo" -c 3 A < mapfile.data 15 | mapfile -C "echo" -c 19 A < mapfile.data 16 | 17 | declare -a C 18 | mapfile -t -u 3 C 3< mapfile.data < mapfile.tests 19 | for (( i = 0 ; i < ${#C[@]} ; i++ )); do 20 | echo "${C[${i}]}" 21 | done 22 | 23 | 24 | declare -a D 25 | for (( i = 0 ; i < 30; i++ )); do 26 | D[${i}]="[$i] aaa" 27 | done 28 | mapfile -O 10 -t D < mapfile.data 29 | for (( i = 0 ; i < ${#D[@]} ; i++ )); do 30 | echo "${D[${i}]}" 31 | done 32 | 33 | declare -a E 34 | for (( i = 0 ; i < 30; i++ )); do 35 | E[${i}]="[$i] aaa" 36 | done 37 | mapfile -O 10 -n 5 -t E < mapfile.data 38 | for (( i = 0 ; i < ${#E[@]} ; i++ )); do 39 | echo "${E[${i}]}" 40 | done 41 | 42 | ${THIS_SH} ./mapfile1.sub 43 | -------------------------------------------------------------------------------- /tests/nquote.right: -------------------------------------------------------------------------------- 1 | argv[1] = <^J^J^J> 2 | argv[1] = <++^J++> 3 | argv[1] = <> 4 | argv[1] = <^J^I > 5 | argv[1] = 6 | argv[1] = <^M^[^Gabc> 7 | argv[1] = 8 | argv[2] = 9 | argv[1] = 10 | argv[1] = <> 11 | argv[1] = <$hello, world> 12 | argv[1] = 13 | argv[1] = 14 | argv[1] = 15 | argv[1] = 16 | argv[1] = <$hello, chet> 17 | argv[1] = 18 | ok 19 | 'abcd' 20 | 'abcd' 21 | \'abcd\' 22 | \'abcd\' 23 | argv[1] = 24 | argv[1] = 25 | argv[1] = 26 | A\CB 27 | A\CB 28 | A\CB 29 | argv[1] = 30 | argv[1] = 31 | argv[1] = 32 | argv[1] = 33 | 1 34 | 1 35 | ;foo 36 | argv[1] = <^I> 37 | argv[1] = <'A^IB'> 38 | hello' world 39 | hello world! 40 | hello' world! 41 | ' | ' 42 | ' | ' 43 | x | x 44 | x | x 45 | ' | ' 46 | ' | ' 47 | ' | ' 48 | ' | ' 49 | ' | ' 50 | ' | ' 51 | x | x 52 | ' 53 | $'\'' 54 | ' 55 | 'abcd' 56 | $'\'abcd\'' 57 | ' 58 | 1 59 | -------------------------------------------------------------------------------- /lib/intl/ref-del.sin: -------------------------------------------------------------------------------- 1 | # Remove this package from a list of references stored in a text file. 2 | # 3 | # Copyright (C) 2000 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 | # Written by Bruno Haible . 19 | # 20 | /^# Packages using this file: / { 21 | s/# Packages using this file:// 22 | s/ @PACKAGE@ / / 23 | s/^/# Packages using this file:/ 24 | } 25 | -------------------------------------------------------------------------------- /lib/termcap/ltcap.h: -------------------------------------------------------------------------------- 1 | /* ltcap.h - Local declarations for termcap library. */ 2 | 3 | /* Copyright (C) 1999-2009 Free Software Foundation, Inc. 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 | #ifndef _LTCAP_H_ 20 | #define _LTCAP_H_ 1 21 | 22 | #if !defined (__APPLE__) 23 | # define __private_extern__ 24 | #endif 25 | 26 | #ifndef MAX_TGETENT_BUFSIZ 27 | # define MAX_TGETENT_BUFSIZ 2048 28 | #endif 29 | 30 | #endif /* _LTCAP_H_ */ 31 | -------------------------------------------------------------------------------- /tests/new-exp2.sub: -------------------------------------------------------------------------------- 1 | export LC_ALL=C 2 | export LANG=C 3 | 4 | # test out the new $(< filename) code 5 | # it should be exactly equivalent to $(cat filename) 6 | 7 | FILENAME=/tmp/bashtmp.x$$ 8 | 9 | trap 'rm -f $FILENAME' 0 10 | 11 | cat >$FILENAME << EOF 12 | line 1 13 | line 2 14 | line 3 15 | EOF 16 | 17 | LINES1=$(cat $FILENAME) 18 | LINES2=$(< $FILENAME) 19 | 20 | if [[ $LINES1 != $LINES2 ]]; then 21 | echo 'whoops: $(< filename) failed' 22 | fi 23 | 24 | LINES2=$(< /tmp/bashtmp.x*) 25 | if [[ $LINES1 != $LINES2 ]]; then 26 | echo 'whoops: $(< filename) with glob expansion failed' 27 | fi 28 | 29 | # but the glob expansion in the redirection should fail in posix mode 30 | set -o posix 31 | LINES2=$(< /tmp/bashtmp.x*) 32 | set +o posix 33 | 34 | # now see what happens when we try it with a non-existant file 35 | LINES3=$(< /tmp/redir-notthere) 36 | echo $? 37 | 38 | # These were bugs through bash-4.2 39 | { : "$({xxxxxxxxxxxxxxxxxxxx} 29 | # posted to usenet as <4i5p17$bnu@larry.rice.edu> 30 | function alias () 31 | { 32 | if [ "x$2" = "x" ] 33 | then 34 | declare -f $1 35 | else 36 | case $2 in 37 | *[#\!]*) 38 | comm=$(echo $2 | sed 's/\\!\*/\"$\@\"/g 39 | s/\\!:\([1-9]\)/\"$\1\"/g 40 | s/#/\\#/g') 41 | ;; 42 | *) 43 | comm="$2 \"\$@\"" ;; 44 | esac 45 | 46 | eval function $1 \(\) "{" command "$comm" "; }" 47 | fi 48 | } 49 | -------------------------------------------------------------------------------- /examples/startup-files/bash-profile: -------------------------------------------------------------------------------- 1 | # This is the filename where your incoming mail arrives. 2 | MAIL=~/mbox 3 | MAILCHECK=30 4 | 5 | HISTFILE=~/.history/history.$HOSTNAME 6 | 7 | PATH1=/usr/homes/chet/bin.$HOSTTYPE:/usr/local/bin/gnu: 8 | PATH2=/usr/local/bin:/usr/ucb:/bin:/usr/bin/X11:. 9 | PATH3=/usr/bin:/usr/new/bin:/usr/contrib/bin 10 | PATH=$PATH1:$PATH2:$PATH3 11 | 12 | EDITOR=/usr/local/bin/ce VISUAL=/usr/local/bin/ce FCEDIT=/usr/local/bin/ce 13 | 14 | SHELL=${SHELL:-${BASH:-/bin/bash}} 15 | 16 | PAGER=/usr/local/bin/less 17 | LESS='-i -e -M -P%t?f%f :stdin .?pb%pb\%:?lbLine %lb:?bbByte %bb:-...' 18 | # 19 | # Bogus 1003.2 variables. This should really be in /etc/profile 20 | # 21 | LOGNAME=${USER-$(whoami)} 22 | TZ=US/Eastern 23 | 24 | export HOME VISUAL EDITOR MAIL SHELL PATH TERM 25 | export PAGER LESS TERMCAP HISTSIZE HISTFILE MAIL MAILCHECK LOGNAME TZ 26 | 27 | PS1="${HOSTNAME}\$ " 28 | PS2='> ' 29 | export PS1 PS2 30 | 31 | umask 022 32 | 33 | if [ -f /unix ] ; then 34 | stty intr ^c # bogus 35 | fi 36 | 37 | if [ -f ~/.bashrc ] ; then 38 | . ~/.bashrc 39 | fi 40 | -------------------------------------------------------------------------------- /lib/sh/strtoul.c: -------------------------------------------------------------------------------- 1 | /* strtoul - convert string representation of a number into an unsigned long value. */ 2 | 3 | /* Copyright (C) 1997 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 | #ifndef HAVE_STRTOUL 24 | 25 | #define UNSIGNED 1 26 | #undef HAVE_STRTOL 27 | 28 | #include 29 | 30 | #endif /* !HAVE_STRTOUL */ 31 | -------------------------------------------------------------------------------- /tests/tilde2.tests: -------------------------------------------------------------------------------- 1 | HOME=/usr/xyz 2 | XPATH=/bin:/usr/bin:. 3 | 4 | ADDPATH=PATH=~/bin:$XPATH 5 | 6 | echo $ADDPATH 7 | 8 | unset ADDPATH 9 | : ${ADDPATH:=~/bin:~/bin2:$XPATH} 10 | echo $ADDPATH 11 | 12 | unset ADDPATH 13 | : ${ADDPATH:=PATH=~/bin:~/bin2:$XPATH} 14 | echo $ADDPATH 15 | 16 | cat << ! 17 | ~/bin 18 | ! 19 | 20 | echo "~" 21 | 22 | echo ${TPATH:-~} 23 | echo "${TPATH:-~}" 24 | echo "${TPATH:-"~"}" 25 | 26 | echo "${XPATH+~}" 27 | 28 | recho "\a" 29 | recho "${TPATH:-\a}" 30 | 31 | SHELL=~/bash 32 | echo $SHELL 33 | 34 | case $SHELL in 35 | ~/bash) echo ok;; 36 | *) echo bad;; 37 | esac 38 | 39 | somevar= 40 | echo "${somevar:-~}" 41 | echo "${somevar:-"~"}" 42 | 43 | echo make -k FOO=~/mumble 44 | 45 | typeset FOO=~/mumble 46 | echo "$FOO" 47 | 48 | h=HOME=~ 49 | echo $h 50 | 51 | export h=HOME=~ 52 | echo $h 53 | 54 | x=1234 55 | HOME='/usr/$x/abc' 56 | 57 | echo ~ 58 | 59 | # behavior differs here in posix mode 60 | set -o posix 61 | 62 | eval echo $h 63 | eval $h 64 | echo $HOME 65 | 66 | set +o posix 67 | 68 | eval echo $h 69 | eval $h 70 | echo $HOME 71 | -------------------------------------------------------------------------------- /tests/redir7.sub: -------------------------------------------------------------------------------- 1 | # weird redirections that caused trouble and were fixed in post-3.0 bash 2 | stuff() 3 | { 4 | c=1 5 | ( sleep 5 < /dev/null >/dev/null 2>&1 & ) & 6 | } 7 | 8 | exec 3>&1 9 | eval ` 10 | exec 4>&1 >&3 3>&- 11 | { 12 | stuff 4>&- 13 | echo "c=$c" >&4 14 | }` 15 | echo c1 is $c 16 | 17 | unset -f stuff 18 | 19 | stuff() 20 | { 21 | c=2 22 | ( sleep 5 < /dev/null >/dev/null 2>&1 & ) 23 | } 24 | 25 | exec 3>&1 26 | eval ` 27 | exec 4>&1 >&3 3>&- 28 | { 29 | stuff 4>&- 30 | echo "c=$c" >&4 31 | }` 32 | echo c2 is $c 33 | 34 | unset -f stuff 35 | 36 | stuff() 37 | { 38 | c=3 39 | { sleep 5 < /dev/null >/dev/null 2>&1 & } & 40 | } 41 | 42 | exec 3>&1 43 | eval ` 44 | exec 4>&1 >&3 3>&- 45 | { 46 | stuff 4>&- 47 | echo "c=$c" >&4 48 | }` 49 | echo c3 is $c 50 | 51 | unset -f stuff 52 | 53 | stuff() 54 | { 55 | c=4 56 | { sleep 5 < /dev/null >/dev/null 2>&1 & } 57 | } 58 | 59 | exec 3>&1 60 | eval ` 61 | exec 4>&1 >&3 3>&- 62 | { 63 | stuff 4>&- 64 | echo "c=$c" >&4 65 | }` 66 | echo c4 is $c 67 | 68 | # fixed in bash-3.1 69 | echo 'exec <&3' | ${THIS_SH} 3<&0 70 | -------------------------------------------------------------------------------- /tests/run-minimal: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # 3 | # run-minimal - a version of run-all for shells configured with 4 | # --enable-minimal-config 5 | # 6 | PATH=.:$PATH # just to get the right version of printenv 7 | export PATH 8 | 9 | # unset BASH_ENV only if it is set 10 | [ "${BASH_ENV+set}" = "set" ] && unset BASH_ENV 11 | # ditto for SHELLOPTS 12 | #[ "${SHELLOPTS+set}" = "set" ] && unset SHELLOPTS 13 | 14 | : ${THIS_SH:=../bash} 15 | export THIS_SH 16 | 17 | ${THIS_SH} ./version.mini 18 | 19 | rm -f /tmp/xx 20 | 21 | echo Testing ${THIS_SH} 22 | echo Any output from any test, unless otherwise noted, indicates a possible anomaly 23 | for x in run-* 24 | do 25 | case $x in 26 | $0) ;; 27 | *.orig|*~) ;; 28 | run-dollars|run-execscript|run-func|run-getopts|run-heredoc) echo $x ; sh $x ;; 29 | run-ifs-tests|run-input-test|run-invert|run-more-exp|run-nquote) echo $x ; sh $x ;; 30 | run-ifs-posix|run-posix2|run-posixpat|run-posixpipe) echo $x ; sh $x ;; 31 | run-precedence|run-quote|run-read|run-rhs-exp|run-strip|run-tilde) echo $x ; sh $x ;; 32 | *) ;; 33 | esac 34 | done 35 | 36 | exit 0 37 | -------------------------------------------------------------------------------- /lib/sh/fmtullong.c: -------------------------------------------------------------------------------- 1 | /* fmtullong.c - convert `long long int' to string */ 2 | 3 | /* Copyright (C) 2001-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 | #ifdef HAVE_LONG_LONG 24 | 25 | #define LONG long long 26 | #define UNSIGNED_LONG unsigned long long 27 | #define fmtulong fmtullong 28 | 29 | #include "fmtulong.c" 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /tests/globstar2.sub: -------------------------------------------------------------------------------- 1 | shopt -s globstar 2 | s() 3 | { 4 | printf '== <%s> ==\n' "$@" 5 | } 6 | p() 7 | { 8 | printf '<%q>\n' "$@" 9 | } 10 | 11 | mkdir -p /tmp/empty/a/a/a 12 | cd /tmp/empty 13 | 14 | # good 15 | p ** 16 | p **/** 17 | p **/**/** 18 | 19 | rm -rf a 20 | mkdir -p /tmp/empty/{a,b}/{a,b}/{a,b}/{a,b} 21 | cd /tmp/empty 22 | 23 | # good 24 | s '**/a' 25 | p **/a 26 | 27 | # good 28 | s 'a/**' 29 | p a/** 30 | 31 | # good 32 | s '**' 33 | p ** 34 | 35 | # good 36 | s '**/**' 37 | p **/** 38 | 39 | # good 40 | s '**/**/**' 41 | p **/**/** 42 | 43 | # good 44 | s '**/**/**/**/**' 45 | p **/**/**/**/** 46 | 47 | # good 48 | s '**/**/a' 49 | p **/**/a 50 | 51 | # good 52 | s 'a/**/**' 53 | p a/**/** 54 | 55 | # good 56 | s 'a/**/**/**' 57 | p a/**/**/** 58 | 59 | # good 60 | s 'a/**/**/**/**' 61 | p a/**/**/**/** 62 | 63 | # same as ksh93 64 | s '**/a/**' 65 | p **/a/** 66 | 67 | # same as ksh93 68 | s '**/a/**/**' 69 | p **/a/**/** 70 | 71 | # same as ksh93 72 | s '**/a/**/**/**' 73 | p **/a/**/**/** 74 | 75 | # good 76 | s '**/**/a/**' 77 | p **/**/a/** 78 | 79 | cd - 80 | rm -rf /tmp/empty 81 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | autom4te.cache 2 | builtins 3 | doc 4 | examples/loadables 5 | examples/loadables/perl 6 | lib/glob 7 | lib/intl 8 | lib/malloc 9 | lib/readline 10 | lib/sh 11 | lib/termcap 12 | lib/tilde 13 | po 14 | support 15 | alias.o 16 | arrayfunc.o 17 | array.o 18 | assoc.o 19 | bash 20 | bashbug 21 | bashhist.o 22 | bashline.o 23 | bashversion 24 | bracecomp.o 25 | braces.o 26 | .build 27 | buildsignames.o 28 | buildversion.o 29 | config.h 30 | config.log 31 | config.status 32 | copy_cmd.o 33 | dispose_cmd.o 34 | error.o 35 | eval.o 36 | execute_cmd.o 37 | expr.o 38 | findcmd.o 39 | flags.o 40 | general.o 41 | hashcmd.o 42 | hashlib.o 43 | input.o 44 | jobs.o 45 | list.o 46 | locale.o 47 | lsignames.h 48 | .made 49 | mailcheck.o 50 | make_cmd.o 51 | Makefile 52 | mksignames 53 | mksignames.o 54 | mksyntax 55 | pathexp.o 56 | pathnames.h 57 | pcomplete.o 58 | pcomplib.o 59 | print_cmd.o 60 | redir.o 61 | shell.o 62 | signames.h 63 | sig.o 64 | stamp-h 65 | stringlib.o 66 | subst.o 67 | syntax.c 68 | syntax.o 69 | test.o 70 | trap.o 71 | unwind_prot.o 72 | variables.o 73 | version.h 74 | version.o 75 | xmalloc.o 76 | y.tab.o 77 | -------------------------------------------------------------------------------- /tests/posixexp.right: -------------------------------------------------------------------------------- 1 | a 2 | b 3 | a b 4 | argv[1] = 5 | argv[2] = 6 | argv[3] = 7 | argv[4] = 8 | argv[5] = 9 | argv[1] = 10 | argv[2] = 11 | argv[3] = 12 | argv[1] = 13 | argv[1] = 14 | argv[1] = 15 | argv[1] = 16 | argv[2] = <}> 17 | argv[3] = 18 | argv[1] = <'foo'> 19 | argv[1] = <'foo'> 20 | argv[1] = <$a> 21 | argv[1] = <'foo'> 22 | argv[1] = 23 | argv[1] = 24 | argv[1] = 25 | argv[1] = 26 | <.> <.> <> <.> <.> 27 | <.> <.> <.> <.> 28 | <.> <.> <.> <.> 29 | <.> <.> <.> <.> 30 | <.> <.> <> <.> <.> 31 | <.> <.> <> <.> <.> 32 | <.> <.> <.> <.> 33 | <.> <.> <.> <.> 34 | <.> <.> <.> <.> 35 | <.> <.> <.> <.> 36 | argv[1] = <'bar> 37 | argv[1] = 38 | argv[1] = <}z> 39 | argv[1] = <''z}> 40 | ./posixexp.tests: line 77: unexpected EOF while looking for matching `}' 41 | ./posixexp.tests: line 78: syntax error: unexpected end of file 42 | -------------------------------------------------------------------------------- /lib/sh/strtoll.c: -------------------------------------------------------------------------------- 1 | /* strtoll - convert string representation of a number into a long long value. */ 2 | 3 | /* Copyright (C) 1997 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 | #if defined (HAVE_LONG_LONG) && !defined (HAVE_STRTOLL) 24 | 25 | #define QUAD 1 26 | #undef HAVE_STRTOL 27 | 28 | #include "strtol.c" 29 | 30 | #endif /* HAVE_LONG_LONG && !HAVE_STRTOLL */ 31 | -------------------------------------------------------------------------------- /lib/intl/ref-add.sin: -------------------------------------------------------------------------------- 1 | # Add this package to a list of references stored in a text file. 2 | # 3 | # Copyright (C) 2000 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 | # Written by Bruno Haible . 19 | # 20 | /^# Packages using this file: / { 21 | s/# Packages using this file:// 22 | ta 23 | :a 24 | s/ @PACKAGE@ / @PACKAGE@ / 25 | tb 26 | s/ $/ @PACKAGE@ / 27 | :b 28 | s/^/# Packages using this file:/ 29 | } 30 | -------------------------------------------------------------------------------- /tests/nameref5.sub: -------------------------------------------------------------------------------- 1 | # nameref variables as for loop index variables are special 2 | v1=1 3 | v2=2 4 | 5 | # simple for loop 6 | for v in v1 v2 7 | do 8 | typeset -n ref=$v 9 | echo $ref 10 | done 11 | unset v 12 | 13 | set -- first second third fourth fifth 14 | 15 | # unless you put a ${!v} in the for loop, ksh93 misbehaves 16 | typeset -n v=v1 17 | for v in v1 v2; do 18 | echo "${!v}: $v" 19 | done 20 | unset v 21 | 22 | # example cribbed from ksh93 o'reilly book 23 | first="I am first" 24 | second="I am in the middle" 25 | third="I am last" 26 | 27 | typeset -n ref=first 28 | for ref in first second third ; do 29 | echo "ref -> ${!ref}, value: $ref" 30 | done 31 | echo final state: "ref -> ${!ref}, value: $ref" 32 | 33 | readonly one=1 34 | readonly two=2 35 | readonly three=3 36 | 37 | typeset -n ref=one 38 | for ref in one two three; do 39 | echo "ref -> ${!ref}, value: $ref" 40 | done 41 | echo final state: "ref -> ${!ref}, value: $ref" 42 | 43 | unset ref 44 | typeset -n ref=one 45 | readonly ref 46 | 47 | for ref in one two three; do 48 | echo "ref -> ${!ref}, value: $ref" 49 | done 50 | echo final state: "ref -> ${!ref}, value: $ref" 51 | -------------------------------------------------------------------------------- /lib/sh/strtoull.c: -------------------------------------------------------------------------------- 1 | /* strtoull - convert string representation of a number into an unsigned long long value. */ 2 | 3 | /* Copyright (C) 1997 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 | #if defined (HAVE_LONG_LONG) && !defined (HAVE_STRTOULL) 24 | 25 | #define QUAD 1 26 | #define UNSIGNED 1 27 | #undef HAVE_STRTOL 28 | 29 | #include "strtol.c" 30 | 31 | #endif /* HAVE_LONG_LONG && !HAVE_STRTOULL */ 32 | -------------------------------------------------------------------------------- /examples/misc/aliasconv.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # 3 | # aliasconv.sh - convert csh aliases to bash aliases and functions 4 | # 5 | # usage: aliasconv.sh 6 | # 7 | # Chet Ramey 8 | # chet@po.cwru.edu 9 | # 10 | trap 'rm -f $TMPFILE' 0 1 2 3 6 15 11 | TMPFILE=$(mktemp -t cb.XXXXXX) || exit 1 12 | T=' ' 13 | 14 | cat << \EOF >$TMPFILE 15 | mkalias () 16 | { 17 | case $2 in 18 | '') echo alias ${1}="''" ;; 19 | *[#\!]*) 20 | comm=`echo $2 | sed 's/\\!\*/"$\@"/g 21 | s/\\!:\([1-9]\)/"$\1"/g 22 | s/#/\#/g'` 23 | echo $1 \(\) "{" command "$comm" "; }" 24 | ;; 25 | *) echo alias ${1}=\'`echo "${2}" | sed "s:':'\\\\\\\\'':"`\' ;; 26 | esac 27 | } 28 | EOF 29 | 30 | # the first thing we want to do is to protect single quotes in the alias, 31 | # since they whole thing is going to be surrounded by single quotes when 32 | # passed to mkalias 33 | 34 | sed -e "s:':\\'\\\'\\':" -e "s/^\([a-zA-Z0-9_-]*\)$T\(.*\)$/mkalias \1 '\2'/" >>$TMPFILE 35 | 36 | sh $TMPFILE | sed -e 's/\$cwd/\$PWD/g' \ 37 | -e 's/\$term/\$TERM/g' \ 38 | -e 's/\$home/\$HOME/g' \ 39 | -e 's/\$user/\$USER/g' \ 40 | -e 's/\$prompt/\$PS1/g' 41 | 42 | exit 0 43 | -------------------------------------------------------------------------------- /tests/exec6.sub: -------------------------------------------------------------------------------- 1 | # builtins with exit status inverted 2 | 3 | ( true ) 4 | echo $? 5 | ( ! true ) 6 | echo $? 7 | 8 | ( false ) 9 | echo $? 10 | ( ! false ) 11 | echo $? 12 | 13 | # inverting shouldn't affect exit 14 | (exit 42) 15 | echo $? 16 | 17 | ( ! exit 42 ) 18 | echo $? 19 | 20 | # commands requiring an exec with exit status inverted -- broken in bash-2.04 21 | 22 | ( ls > /dev/null 2>&1 ) 23 | echo $? 24 | ( ! ls > /dev/null 2>&1 ) 25 | echo $? 26 | 27 | touch /tmp/notwrite 28 | chmod 400 /tmp/notwrite 29 | 30 | # make sure redirection failures in commands whose exit status is inverted 31 | # are handled correctly 32 | 33 | ( ls > /tmp/notwrite ) 2>/dev/null 34 | echo $? 35 | 36 | ( ! ls > /tmp/notwrite ) 2>/dev/null 37 | echo $? 38 | 39 | # now add exit traps, true and false for commands with and without exit 40 | # status inversion 41 | 42 | (trap 'false' 0 ; ! ls > /tmp/notwrite ) 2>/dev/null 43 | echo $? 44 | 45 | (trap 'false' 0 ; ls > /tmp/notwrite ) 2>/dev/null 46 | echo $? 47 | 48 | (trap 'true' 0 ; ! ls > /tmp/notwrite ) 2>/dev/null 49 | echo $? 50 | 51 | (trap 'true' 0 ; ls > /tmp/notwrite ) 2>/dev/null 52 | echo $? 53 | 54 | rm -f /tmp/notwrite 55 | -------------------------------------------------------------------------------- /tests/exec.right: -------------------------------------------------------------------------------- 1 | before exec1.sub: one two three 2 | calling exec1.sub 3 | aa bb cc dd ee 4 | after exec1.sub with args: 0 5 | 6 | after exec1.sub without args: 0 7 | after exec1.sub: one two three 8 | ./execscript: line 21: notthere: command not found 9 | 127 10 | /tmp/bash: notthere: No such file or directory 11 | 127 12 | /bin/sh: /bin/sh: cannot execute binary file 13 | 126 14 | ./execscript: line 40: /: Is a directory 15 | 126 16 | /: /: is a directory 17 | 126 18 | ./execscript: line 47: .: /: is a directory 19 | 1 20 | 126 21 | 0 22 | this is bashenv 23 | ./exec3.sub: line 3: /tmp/bash-notthere: No such file or directory 24 | 127 25 | ./execscript: line 71: notthere: No such file or directory 26 | 127 27 | ./execscript: line 74: notthere: No such file or directory 28 | 127 29 | ./execscript: line 77: notthere: command not found 30 | 127 31 | this is sh 32 | this is sh 33 | unset 34 | ok 35 | 5 36 | ./exec5.sub: line 4: exec: bash-notthere: not found 37 | 127 38 | this is ohio-state 39 | 0 40 | 1 41 | 1 42 | 0 43 | 42 44 | 42 45 | 0 46 | 1 47 | 1 48 | 0 49 | 0 50 | 1 51 | 0 52 | 1 53 | testb 54 | expand_aliases on 55 | 1 56 | 1 57 | 1 58 | 1 59 | 0 60 | 0 61 | 0 62 | 0 63 | after 64 | -------------------------------------------------------------------------------- /lib/malloc/xleaktrace: -------------------------------------------------------------------------------- 1 | #! /usr/bin/awk -f 2 | # 3 | # xleaktrace - print unfreed memory using input generated by compact malloc 4 | # tracing (malloc_set_trace(1)) 5 | # 6 | # NOTE: we ignore `realloc' tags because they're just extra information 7 | # 8 | # Copyright (c) 2001 Chester Ramey 9 | # Permission is hereby granted to deal in this Software without restriction. 10 | # THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. 11 | # 12 | # Chet Ramey 13 | # chet@po.cwru.edu 14 | # 15 | BEGIN { 16 | FS=":"; 17 | } 18 | 19 | $1 == "alloc" { 20 | alloc[$2] = 1; 21 | 22 | size[$2] = $3; 23 | file[$2] = $4; 24 | line[$2] = $5; 25 | 26 | # printf "allocated: %s %d %d %s %d\n", $2, alloc[$2], size[$2], file[$2], line[$2]; 27 | } 28 | 29 | $1 == "free" { 30 | if ($2 in alloc) { 31 | alloc[$2] = 0; 32 | # printf "freed: %s %d\n", $2, alloc[$2]; 33 | } else 34 | printf "freeing unallocated pointer: %s\n", $2; 35 | 36 | } 37 | 38 | END { 39 | printf "unfreed memory\n"; 40 | for (ptr in alloc) { 41 | if (alloc[ptr] == 1) { 42 | printf "%s (%d) from %s:%d\n", ptr, size[ptr], file[ptr], line[ptr]; 43 | } 44 | } 45 | } 46 | 47 | 48 | -------------------------------------------------------------------------------- /examples/misc/aliasconv.bash: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # 3 | # aliasconv.bash - convert csh aliases to bash aliases and functions 4 | # 5 | # usage: aliasconv.bash 6 | # 7 | # Chet Ramey 8 | # chet@po.cwru.edu 9 | # 10 | trap 'rm -f $TMPFILE' 0 1 2 3 6 15 11 | 12 | TMPFILE=$(mktemp -t cb.XXXXXX) || exit 1 13 | 14 | T=$'\t' 15 | 16 | cat << \EOF >$TMPFILE 17 | mkalias () 18 | { 19 | case $2 in 20 | '') echo alias ${1}="''" ;; 21 | *[#\!]*) 22 | comm=$(echo $2 | sed 's/\!\*/"$\@"/g 23 | s/\!:\([1-9]\)/"$\1"/g 24 | s/#/\#/g') 25 | echo $1 \(\) "{" command "$comm" "; }" 26 | ;; 27 | *) echo alias ${1}=\'$(echo "${2}" | sed "s:':'\\\\'':g")\' ;; 28 | esac 29 | } 30 | EOF 31 | 32 | # the first thing we want to do is to protect single quotes in the alias, 33 | # since they whole thing is going to be surrounded by single quotes when 34 | # passed to mkalias 35 | 36 | sed -e "s:':\\'\\\'\\':" -e "s/^\([a-zA-Z0-9_-]*\)$T\(.*\)$/mkalias \1 '\2'/" >>$TMPFILE 37 | 38 | $BASH $TMPFILE | sed -e 's/\$cwd/\$PWD/g' \ 39 | -e 's/\$term/\$TERM/g' \ 40 | -e 's/\$home/\$HOME/g' \ 41 | -e 's/\$user/\$USER/g' \ 42 | -e 's/\$prompt/\$PS1/g' 43 | 44 | exit 0 45 | --------------------------------------------------------------------------------