• Home
  • Raw
  • Download

Lines Matching +full:exec +full:- +full:sh

3 [ -f testing.sh ] && . testing.sh
10 # Use "bash" name for host, "sh" for toybox. (/bin/sh is often defective.)
11 [ -z "$SH" ] && { [ -z "$TEST_HOST" ] && SH="sh" || export SH="bash" ; }
13 [ $UID -eq 0 ] && P='# ' || P='$ '
15 SS="env -i PATH=${PATH@Q} PS1='\\$ ' $SH --noediting --noprofile --norc -is"
30 # Test shell command line (-c and how scripts run) before changing EVAL
31 testing '-c "" exit status 0' '$SH -c "" && echo $?' '0\n' '' ''
32 testing '-c args' "\$SH -c 'echo \$0,\$1,\$2,\$3' one two three four five" \
34 testing '-c args2' "\$SH -c 'echo \${10}' a b c d e f g h i j k l" "k\n" "" ""
35 testing '-c arg split' \
36 "$SH -c 'for i in a\"\$@\"b;do echo =\$i=;done;echo \$0' 123 456 789" \
38 testing '-c arg split2' \
39 "$SH -c 'for i in a\"\$* \$@\"b; do echo =\$i=;done' one two three four five"\
41 testing '-c arg count' "$SH -c 'echo \$#' 9 8 7 6 1 2 3 4" "7\n" "" ""
42 testing 'trailing \' "$SH -c 'echo \'" '\\\n' '' ''
43 testing "trailing \\ in ''" "$SH -c \$'echo \\'one\\\\\\ntwo\\''" \
45 testing 'trailing \ in ""' "$SH -c \$'echo \"one\\\\\\ntwo\"'" 'onetwo\n' \
47 testing 'vanishing \' "$SH -c \$'echo \\\\\\n a'" 'a\n' '' ''
48 testing 'command\ arg' "$SH -c \$'echo\\\\\\n abc'" 'abc\n' '' ''
49 testing "exec3" '$C -c "{ exec readlink /proc/self/fd/0;} < /proc/self/exe"' \
50 "$(readlink -f $C)\n" "" ""
51 testing 'arg shift' "$SH -c '"'for i in "" 2 1 1 1; do echo $? $1; shift $i; done'"' one two three …
53 testing '(subshell)' '$SH -c "(echo hello)"' 'hello\n' '' ''
54 testing 'syntax' '$SH -c "if true; then echo hello | fi" 2>/dev/null || echo x'\
56 testing 'syntax2' '$SH -c "for;i 0" 2>&1 | { grep -qi syntax && echo yes; }' \
60 ln -s "$(which $SH)" bash
61 testing 'non-absolute $_' "./bash -c 'echo \$_'" './bash\n' '' ''
64 testing 'exec exitval' "$SH -c 'exec echo hello' && echo \$?" "hello\n0\n" "" ""
65 testing 'simple script' '$SH input' 'input\n' 'echo $0' ''
66 testing 'simple script2' '$SH ./input two;echo $?' './input+two\n42\n' \
70 '$SH input 2>/dev/null; [ $? -lt 128 ] && echo pass' 'pass\n' \
72 testing '$LINENO 1' "$SH input" "1\n" 'echo $LINENO' ''
76 testing 'simple script in $PATH' "PATH='$PWD/sub:$PATH' $SH script" \
78 rm -rf sub
81 testing 'IFS $*' "$SH -c 'IFS=xy; echo \"\$*\"' one two tyree" "twoxtyree\n" \
85 "env -i \"$(which $SH)\" --noprofile --norc -c \$'env\n\n' | sort" \
89 # "{ \$SH -c 'X=\${a?blah} > walroid';ls walroid;} 2>/dev/null" '' '' ''
90 testing "lineno" "$SH input" "5 one\n6 one\n5 two\n6 two\n" \
92 testing "eval0" "$SH -c 'eval echo \$*' one two three" "two three\n" "" ""
95 # Change EVAL to call sh -c for us, using "bash" explicitly for the host.
96 export EVAL="timeout 10 $SH -c"
102 testing 'return code 3' 'x=0; while [ $((x++)) -lt 2 ]; do echo $x; done; echo $?' '1\n2\n0\n' '' ''
107 testing 'escape passthrough' 'echo -e "a\nb\nc\td"' 'a\nb\nc\td\n' '' ''
111 testing '<<\EOF' $'(cat<<EOF\n$PATH\nEOF\necho "$PATH") | sort -u | wc -l' \
113 testing "<<EOF''" $'(cat<<EOF\'\'\n$PATH\nEOF\necho "$PATH") | sort -u | wc -l'\
115 testing '<<\EOF' $'(cat<<\\EOF\n$PATH\nEOF\necho "$PATH") | sort -u | wc -l' \
132 ln -s "$(which echo)" echo2
135 rm -f echo2
140 testing 'escape makes argument' 'echo \ | wc -c' '2\n' '' ''
150 shxpect '$_ preserved on exec error' I$'true hello; ${}\n' \
152 shxpect '$_ abspath on exec' I$'env | grep ^_=\n' O$'_=/usr/bin/env\n'
153 testing '$_ literal after exec' 'env >/dev/null; echo $_' 'env\n' '' ''
166 mkdir -p one/two/three
168 'cd one/two/three && mv ../../../{one,four} && cd .. && echo ${PWD: -9:9}' \
170 rm -rf one
184 testing "exec" "exec echo hello" "hello\n" "" ""
185 testing "exec2" "exec echo hello; echo $?" "hello\n" "" ""
203 testing "redir4" "touch /not/exist 2>out||grep -o /not/exist out" \
205 testing "redir5" "ls out /not/exist &> out2 || wc -l < out2" "2\n" "" ""
206 testing "redir6" "ls out /not/exist &>>-abc || wc -l < ./-abc" "2\n" "" ""
207 testing "redir7" "ls out /not/exist |& wc -l" "2\n" "" ""
208 testing "redir8" 'echo -n $(<input)' "boing" "boing\n" ""
210 I$'wc -l < out\n' O$'0\n'
214 rm -f out out2 ./-abc
232 for i in /root /var/root /; do [ -e $i ] && EXPECT=$i && break; done
243 testing '${x%glob}' 'x=abc-def; echo ${x%-*f} ${x-*c}' 'abc abc-def\n' '' ''
252 mkdir -p abc/def/ghi
254 testing 'wildcards' 'echo w[v-x]w w[x-v]w abc/*/ghi' \
255 'www w[x-v]w abc/def/ghi\n' '' ''
271 testing "math spaces" 'echo $(( ( 1 + 2 ) * 7 - 5 ** 2 ))' '-4\n' '' ''
277 testing "predecrement" 'echo $((--x)); echo $x' '-1\n-1\n' '' ''
278 testing "predecrement vs prefix minus" 'echo $((---x)); echo $x' '1\n-1\n' '' ''
279 testing "minus-minus-minus" 'echo $((x---7)); echo $x' '-7\n-1\n' '' ''
280 testing "x---y is x-- -y not x- --y" 'x=1 y=1; echo $((x---y)) $x $y' '0 0 1\n'\
314 'while X=$(($X+1)); do echo $X; done | while read i; do echo $i; done | head -n 5' \
341 rm -f walrus
346 testing "{a..z..-3}" "echo {a..z..-3}" "a d g j m p s v y\n" "" ""
352 rm -f POIT
355 'if true; then { sleep .25;bzcat "$FILES"/blkid/ntfs.bz2; }& fi | wc -c' \
365 … for i in $A $B $C $D L$A L$B L$C L$D $A= $B= $C= $D= L$A= L$B= L$C= L$D=; do echo -n {$i}; done' \
377 testing "IFS" 'IFS=x; A=abx; echo -n "$A"' "abx" "" ""
378 testing "IFS2" 'IFS=x; A=abx; echo -n $A' "ab" "" ""
387 testing '$! = jobs -p' 'true & [ $(jobs -p) = $! ] && echo yes' "yes\n" "" ""
396 'cc() { echo ="$*"=; for i in =$*=; do echo -$i-; done;}; cc "" ""; echo and; cc ""' \
397 '= =\n-=-\n-=-\nand\n==\n-==-\n' "" ""
398 testing 'really?' 'cc() { for i in $*; do echo -$i-; done;}; cc "" "" ""' \
420 … for i in $A $B $C $D L$A L$B L$C L$D $A= $B= $C= $D= L$A= L$B= L$C= L$D=; do echo -n {$i}; done' \
451 # Same thing twice, but how do we cmp if exec exited?
452 #testing 'exec and $$' testing 'echo $$;exec readlink /proc/self'
455 testing "exec in paren" \
456 '(exec readlink /proc/self/exe);echo hello' "$X\nhello\n" "" ""
457 testing "exec in brackets" \
458 "{ exec readlink /proc/self/exe;};echo hi" "$X\n" "" ""
507 testing '<<- eats leading tabs before expansion, but not after' \
508 $'A=$\'\\tone\'; cat <<- EOF\n\t\t$A\n\ttwo\nEOF' "\tone\ntwo\n" '' ''
512 testing 'empty ${}' '{ echo ${};} 2>&1 | grep -o bad' 'bad\n' '' ''
515 testing '${$b}' '{ echo ${$b};} 2>&1 | grep -o bad' 'bad\n' '' ''
535 '{ ABC=def; def=ghi; echo ${!ABC@ }; } 2>&1 | grep -o bad' 'bad\n' '' ''
544 testing 'bad ${^}' '{ echo ${^};} 2>&1 | grep -o bad' 'bad\n' '' ''
551 testing '${a :}' 'ABC=def; { echo ${ABC :1};} 2>&1 | grep -o bad' 'bad\n' '' ''
555 'ABC=defghi:1:2; ( echo ${!ABC};) 2>input; [ -s input ] && echo yes' \
557 testing '${::-}' 'ABC=defghi; echo ${ABC:1:-2}' 'efg\n' '' ''
558 testing '${:-:-}' 'ABC=defghi; echo ${ABC:-3:2}' 'defghi\n' '' ''
559 testing '${:-:-}2' 'echo ${ABC:-3:2}' '3:2\n' '' ''
560 testing '${: -:}' 'ABC=defghi; echo ${ABC: -3:2}' 'gh\n' '' ''
580 testing '$EUID' 'echo $EUID' "$(id -u)\n" '' ''
581 testing '$UID' 'echo $UID' "$(id -ur)\n" '' ''
584 '{ readonly abc=123;abc=def echo hello; echo $?;} 2>output; grep -o readonly output' \
602 rm -f walrus wallpapers
605 # of sh -c "str" in one go, meaning the "shopt -s extglob" won't take effect
606 shxpect 'IFS +(extglob)' I$'shopt -s extglob\n' E"$P" \
611 shxpect 'IFS +(extglob) 2' I$'shopt -s extglob\n' E"$P" \
616 shxpect '[+(]) overlap priority' I$'shopt -s extglob\n' E"$P" \
625 shxpect 'trace redirect' I$'set -x; echo one\n' E$'+ echo one\n'"$P" O$'one\n' \
628 shxpect 'set -u' I$'set -u; echo $walrus\n' REwalrus X
649 …'func() { echo one; source <(echo -e "echo hello\necho |") 2>/dev/null; echo three;}; func; echo f…
661 '{ echo $BASHPID; chicken() { echo $BASHPID;}; chicken;} | sort -u | wc -l' '1\n' '' ''
663 '{ echo $BASHPID; chicken() ( echo $BASHPID;); chicken;} | sort -u | wc -l' '2\n' '' ''
679 'x() { local RANDOM=potato; echo $RANDOM;};x;echo -e "$RANDOM\n$RANDOM"|wc -l'\
683 '{ echo $$; (echo $$) } | sort -u | wc -l' "1\n" "" ""
685 '{ echo $PPID; (echo $PPID) } | sort -u | wc -l' "1\n" "" ""
687 '{ echo $BASHPID; (echo $BASHPID) } | sort -u | wc -l' "2\n" "" ""
689 testing 'unexport supports +=' 'export -n ABC+=DEF; declare -p ABC' \
690 'declare -- ABC="DEF"\n' '' ''
692 'export ABC=XYZ; export -n ABC+=DEF; declare -p ABC' \
693 'declare -- ABC="XYZDEF"\n' '' ''
695 testing '$!' '{ echo $BASHPID & echo $!; echo ${!};} | sort -u | wc -l' '1\n' \
704 testing '[[split1]]' 'A="1 -lt 2"; [[ $A ]] && echo yes' 'yes\n' '' ''
705 testing '[[split2]]' 'A="2 -lt 1"; [[ $A ]] && echo yes' 'yes\n' '' ''
707 'A="2 -lt 1"; [[ -e $A ]] && echo one; touch "$A" && [[ -e $A ]] && echo two'\
709 rm -f '2 -lt 1'
717 testing '[[1>2]] is not a redirect' '[[ 1 >2 ]] || [ -e 2 ] || echo yup' \
720 '[[ 1 >0 ]] && { [ -e 2 ] || echo yup; }' 'yup\n' '' ''
726 $'echo -n "$(echo "hello $(eval $\'echo -\\\\\\ne \\\'world\\n \\\'\')")"' \
734 # $# $? $- $! $0 # $$
736 # ./bash -c 'echo $_' prints $BASH, but PATH search shows path? Hmmm...
741 # ENV - if [ -n "$ENV" ]; then . "$ENV"; fi # BASH_ENV - synonym for ENV
742 # FUNCNEST - maximum function nesting level (abort when above)
743 # REPLY - set by input with no args
744 # OPTARG OPTIND - set by getopts builtin
749 #BASH_SUBSHELL - SHLVL synonym
750 #BASH_EXECUTION_STRING - -c argument
753 #OPTARG - set by getopts builtin
754 #OPTIND - set by getopts builtin
760 #GROUPS - id -g
761 #HISTCMD - history number
763 #TMOUT - used by read
765 # does not match: ./sh -c 'echo {a..Z}' becomes a ` _ ^ ] \ [ Z
768 #- IS_TOYBOX_RE='(toybox|This is not GNU).*'
769 #- [[ "$IS_TOYBOX" =~ $IS_TOYBOX_RE ]] || SKIPNEXT=1
780 # https://mywiki.wooledge.org/BashPitfalls#set_-euo_pipefail
785 # Looked like a prefix but wasn't: three chars (@ # -) are both paremeter name
789 # ${#-} ${#-abc}
795 # ${x:-y} use default
799 # ${x:off} ${x:off:len} off<0 from end (must ": -"), len<0 also from end must
800 # 0-based indexing
801 # ${@:off:len} positional parameters, off -1 = len, -len is error
802 # 1-based indexing