#!/bin/echo no # Testing shell corner cases _within_ a shell script is kind of hard. [ -f testing.sh ] && . testing.sh # TODO make fake pty wrapper for test infrastructure #testing "name" "command" "result" "infile" "stdin" [ -z "$SH" ] && { [ -z "$TEST_HOST" ] && SH="sh" || export SH="bash" ; } export EVAL="$SH -c" testing "smoketest" "echo hello" "hello\n" "" "" # ; | && || testing "semicolon" "echo one;echo two" "one\ntwo\n" "" "" testing "simple pipe" "echo hello | cat" "hello\n" "" "" testing "&&" "true && echo hello" "hello\n" "" "" testing "&&2" "false && echo hello" "" "" "" testing "||" "true || echo hello" "" "" "" testing "||2" "false || echo hello" "hello\n" "" "" testing "&& ||" "true && false && potato || echo hello" "hello\n" "" "" # redirection testing "" "cat < input" "hello\n" "hello\n" "" testing "" "echo blah >out; cat out" "blah\n" "" "" testing "" "touch /not/exist 2>out||grep -o /not/exist out" "/not/exist\n" "" "" #testing "" 'echo hello | (read i /dev/full\n" "E" "E$P" X0 txpect "wait for <(exit)" "$SH" "E$P" "Icat <(echo hello 1>&2)\n" $'Ehello\n' \ "E$P" X0 # $@ $* $# $? $- $$ $! $0 # always exported: PWD SHLVL _ # ./bash -c 'echo $_' prints $BASH, but PATH search shows path? Hmmm... # ro: UID PPID EUID $ # IFS LINENO # PATH HOME SHELL USER LOGNAME SHLVL HOSTNAME HOSTTYPE MACHTYPE OSTYPE OLDPWD # PS0 PS1='$ ' PS2='> ' PS3 PS4 BASH BASH_VERSION # ENV - if [ -n "$ENV" ]; then . "$ENV"; fi # BASH_ENV - synonym for ENV # FUNCNEST - maximum function nesting level (abort when above) # REPLY - set by input with no args # OPTARG OPTIND - set by getopts builtin # OPTERR # maybe not: EXECIGNORE, FIGNORE, GLOBIGNORE #BASHPID - synonym for $$ HERE #BASH_SUBSHELL - SHLVL synonym #BASH_EXECUTION_STRING - -c argument # #automatically set: #OPTARG - set by getopts builtin #OPTIND - set by getopts builtin # #PROMPT_COMMAND PROMPT_DIRTRIM PS0 PS1 PS2 PS3 PS4 # #unsettable (assignments ignored before then) #LINENO SECONDS RANDOM #GROUPS - id -g #HISTCMD - history number # #TMOUT - used by read