1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-15 04:32:24 +00:00

Allow regression tests to pass without any /opt/ast/bin builtins (#403)

This commit primarily makes changes that allow the regression tests to
run without any of the /opt/ast/bin builtins compiled into ksh. It also
makes a minor improvement to one of the tests in locale.sh by
shellquoting an error message.

Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
Johnothan King 2021-12-28 08:57:50 -08:00 committed by Martijn Dekker
parent 0e197eee57
commit de795e1f9d
8 changed files with 237 additions and 211 deletions

View file

@ -184,25 +184,27 @@ x=$( ("$binecho" foo) ; ("$binecho" bar) )
if [[ $x != $'foo\nbar' ]]
then err_exit " ( ("$binecho");("$binecho" bar ) failed"
fi
cat > $tmp/script <<\!
if [[ -p /dev/fd/0 ]]
then builtin cat
cat - > /dev/null
[[ -p /dev/fd/0 ]] && print ok
else print no
fi
if (builtin cat) 2> /dev/null; then
cat > $tmp/script <<\!
if [[ -p /dev/fd/0 ]]
then builtin cat
cat - > /dev/null
[[ -p /dev/fd/0 ]] && print ok
else print no
fi
!
chmod +x $tmp/script
case $( (print) | $tmp/script;:) in
ok) ;;
no) err_exit "[[ -p /dev/fd/0 ]] fails for standard input pipe" ;;
*) err_exit "builtin replaces standard input pipe" ;;
esac
print 'print $0' > $tmp/script
print ". $tmp/script" > $tmp/scriptx
chmod +x $tmp/scriptx
if [[ $($tmp/scriptx) != $tmp/scriptx ]]
then err_exit '$0 not correct for . script'
chmod +x $tmp/script
case $( (print) | $tmp/script;:) in
ok) ;;
no) err_exit "[[ -p /dev/fd/0 ]] fails for standard input pipe" ;;
*) err_exit "builtin replaces standard input pipe" ;;
esac
print 'print $0' > $tmp/script
print ". $tmp/script" > $tmp/scriptx
chmod +x $tmp/scriptx
if [[ $($tmp/scriptx) != $tmp/scriptx ]]
then err_exit '$0 not correct for . script'
fi
fi
cd $tmp || { err_exit "cd $tmp failed"; exit 1; }
print ./b > ./a; print ./c > b; print ./d > c; print ./e > d; print "echo \"hello there\"" > e
@ -521,17 +523,18 @@ float sec=SECONDS
. $tmp/foo.sh | cat > /dev/null
(( (SECONDS-sec) < .07 )) && err_exit '. script does not restore output redirection with eval'
file=$tmp/foobar
builtin cat
for ((n=0; n < 1000; n++))
do
> $file
{ sleep .001;echo $? >$file;} | cat > /dev/null
if [[ ! -s $file ]]
then err_exit 'output from pipe is lost with pipe to builtin'
break;
fi
done
if builtin cat 2> /dev/null; then
file=$tmp/foobar
for ((n=0; n < 1000; n++))
do
> $file
{ sleep .001;echo $? >$file;} | cat > /dev/null
if [[ ! -s $file ]]
then err_exit 'output from pipe is lost with pipe to builtin'
break;
fi
done
fi
$SHELL -c 'kill -0 123456789123456789123456789' 2> /dev/null && err_exit 'kill not catching process id overflows'

View file

@ -25,29 +25,30 @@ bincat=$(whence -p cat)
# ======
# These are regression tests for the getconf builtin.
builtin getconf
bingetconf=$(getconf GETCONF)
bad_result=$(getconf --version 2>&1)
if builtin getconf 2> /dev/null; then
bingetconf=$(getconf GETCONF)
bad_result=$(getconf --version 2>&1)
# The -l option should convert all variable names to lowercase.
# https://github.com/att/ast/issues/1171
got=$(getconf -lq | awk '{ gsub(/=.*/, "") } /[[:upper:]]/ { print }')
[[ -n $got ]] && err_exit "'getconf -l' doesn't convert all variable names to lowercase" \
"(got $(printf %q "$got"))"
# The -l option should convert all variable names to lowercase.
# https://github.com/att/ast/issues/1171
got=$(getconf -lq | awk '{ gsub(/=.*/, "") } /[[:upper:]]/ { print }')
[[ -n $got ]] && err_exit "'getconf -l' doesn't convert all variable names to lowercase" \
"(got $(printf %q "$got"))"
# The -q option should quote all string values.
# https://github.com/att/ast/issues/1173
exp="GETCONF=\"$bingetconf\""
got=$(getconf -q | grep 'GETCONF=')
[[ $exp == "$got" ]] || err_exit "'getconf -q' fails to quote string values" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# The -q option should quote all string values.
# https://github.com/att/ast/issues/1173
exp="GETCONF=\"$bingetconf\""
got=$(getconf -q | grep 'GETCONF=')
[[ $exp == "$got" ]] || err_exit "'getconf -q' fails to quote string values" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# The -n option should only return matching names.
# https://github.com/ksh93/ksh/issues/279
exp="GETCONF=$bingetconf"
got=$(getconf -n GETCONF)
[[ $exp == "$got" ]] || err_exit "'getconf -n' doesn't match names correctly" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
# The -n option should only return matching names.
# https://github.com/ksh93/ksh/issues/279
exp="GETCONF=$bingetconf"
got=$(getconf -n GETCONF)
[[ $exp == "$got" ]] || err_exit "'getconf -n' doesn't match names correctly" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
fi
# ======
# Test shell builtin commands
@ -411,14 +412,16 @@ wait $pid1
wait $pid2
(( $? == 127 )) || err_exit "subshell job known to parent"
env=
v=$(getconf LIBPATH)
for v in ${v//,/ }
do v=${v#*:}
v=${v%%:*}
eval [[ \$$v ]] && env="$env $v=\"\$$v\""
done
if [[ $(foo=bar; eval foo=\$foo $env exec -c \$SHELL -c \'print \$foo\') != bar ]]
then err_exit '"name=value exec -c ..." not working'
if builtin getconf 2> /dev/null; then
v=$(getconf LIBPATH)
for v in ${v//,/ }
do v=${v#*:}
v=${v%%:*}
eval [[ \$$v ]] && env="$env $v=\"\$$v\""
done
if [[ $(foo=bar; eval foo=\$foo $env exec -c \$SHELL -c \'print \$foo\') != bar ]]
then err_exit '"name=value exec -c ..." not working'
fi
fi
$SHELL -c 'OPTIND=-1000000; getopts a opt -a' 2> /dev/null
[[ $? == 1 ]] || err_exit 'getopts with negative OPTIND not working'
@ -583,8 +586,10 @@ fi
while (( i <2))
do (( i++))
done) == $'0\n0\n1\n1\n2' ]] || err_exit "DEBUG trap not working"
getconf UNIVERSE - ucb
[[ $($SHELL -c 'echo -3') == -3 ]] || err_exit "echo -3 not working in ucb universe"
if builtin getconf 2> /dev/null; then
getconf UNIVERSE - ucb
[[ $($SHELL -c 'echo -3') == -3 ]] || err_exit "echo -3 not working in ucb universe"
fi
typeset -F3 start_x=SECONDS total_t delay=0.02
typeset reps=50 leeway=5
sleep $(( 2 * leeway * reps * delay )) |
@ -635,11 +640,11 @@ t=$(ulimit -t)
$SHELL 2> /dev/null -c 'cd ""' && err_exit 'cd "" not producing an error'
[[ $($SHELL 2> /dev/null -c 'cd "";print hi') != hi ]] && err_exit 'cd "" should not terminate script'
builtin cat
out=$tmp/seq.out
for ((i=1; i<=11; i++)); do print "$i"; done >$out
cmp -s <(print -- "$($bincat<( $bincat $out ) )") <(print -- "$(cat <( cat $out ) )") || err_exit "builtin cat differs from $bincat"
builtin -d cat
if builtin cat 2> /dev/null; then
out=$tmp/seq.out
for ((i=1; i<=11; i++)); do print "$i"; done >$out
cmp -s <(print -- "$($bincat<( $bincat $out ) )") <(print -- "$(cat <( cat $out ) )") || err_exit "builtin cat differs from $bincat"
fi
[[ $($SHELL -c '{ printf %R "["; print ok;}' 2> /dev/null) == ok ]] || err_exit $'\'printf %R "["\' causes shell to abort'
@ -859,7 +864,8 @@ for w in 'whence -t' 'type -t' 'whence -t -v'; do
got=$($w export)
[[ $exp == "$got" ]] || err_exit "'$w' has the wrong output for special builtins" \
"(expected $(printf %q "$exp"); got $(printf %q "$got"))"
if [[ $(PATH=/opt/ast/bin type cat) != "cat is a shell builtin version of /opt/ast/bin/cat" ]]
builtin -d cat
if [[ $(set +x; PATH=/opt/ast/bin type cat 2>&1) != "cat is a shell builtin version of /opt/ast/bin/cat" ]]
then warning "/opt/ast/bin/cat isn't a builtin; skipping path-bound builtin tests"
else
got=$(PATH=/opt/ast/bin $w cat)
@ -899,15 +905,18 @@ for w in 'whence -t' 'type -t' 'whence -t -v'; do
"(expected $(printf %q "$exp"); got $(printf %q "$got"))"
# The final few tests are for '-t -a'
exp="alias
builtin -d cat
if [[ $(set +x; PATH=/opt/ast/bin type cat 2>&1) == "cat is a shell builtin version of /opt/ast/bin/cat" ]]
then exp="alias
function
builtin
$($w -pa cat)"
got=$(alias cat=false
autoload cat
PATH=/opt/ast/bin:$PATH $w -a cat)
[[ $exp == "$got" ]] || err_exit "'$w -a' output is incorrect (cat command)" \
"(expected $(printf %q "$exp"); got $(printf %q "$got"))"
got=$(alias cat=false
autoload cat
PATH=/opt/ast/bin:$PATH $w -a cat)
[[ $exp == "$got" ]] || err_exit "'$w -a' output is incorrect (cat command)" \
"(expected $(printf %q "$exp"); got $(printf %q "$got"))"
fi
if [[ -n $($w -pa time) ]]
then exp="keyword
alias

View file

@ -39,9 +39,9 @@ function ping # id
}
bincat=$(whence -p cat)
builtin cat
builtin cat 2> /dev/null && builtincat=cat
for cat in cat $bincat
for cat in $builtincat $bincat
do
$cat |&

View file

@ -30,28 +30,29 @@ function abspath
print $newdir/$base
}
# test for proper exit of shell
builtin getconf
ABSHELL=$(abspath)
print exit 0 >.profile
${ABSHELL} <<!
HOME=$PWD \
PATH=$PATH \
SHELL=$ABSSHELL \
$(
v=$(getconf LIBPATH)
for v in ${v//,/ }
do v=${v#*:}
v=${v%%:*}
eval [[ \$$v ]] && eval print -n \" \"\$v=\"\$$v\"
done
) \
exec -c -a -ksh ${ABSHELL} -c "exit 1" 1>/dev/null 2>&1
if builtin getconf 2> /dev/null; then
ABSHELL=$(abspath)
print exit 0 >.profile
${ABSHELL} <<!
HOME=$PWD \
PATH=$PATH \
SHELL=$ABSSHELL \
$(
v=$(getconf LIBPATH)
for v in ${v//,/ }
do v=${v#*:}
v=${v%%:*}
eval [[ \$$v ]] && eval print -n \" \"\$v=\"\$$v\"
done
) \
exec -c -a -ksh ${ABSHELL} -c "exit 1" 1>/dev/null 2>&1
!
status=$(echo $?)
if [[ -o noprivileged && $status != 0 ]]
then err_exit 'exit in .profile is ignored'
elif [[ -o privileged && $status == 0 ]]
then err_exit 'privileged .profile not ignored'
status=$(echo $?)
if [[ -o noprivileged && $status != 0 ]]
then err_exit 'exit in .profile is ignored'
elif [[ -o privileged && $status == 0 ]]
then err_exit 'privileged .profile not ignored'
fi
fi
if [[ $(trap 'code=$?; echo $code; trap 0; exit $code' 0; exit 123) != 123 ]]
then err_exit 'exit not setting $?'
@ -65,7 +66,9 @@ then err_exit 'subshell trap on exit overwrites parent trap'
fi
cd /
cd ~- || err_exit "cd back failed"
$SHELL -c 'builtin -f cmd getconf; getconf --"?-version"; exit 0' >/dev/null 2>&1 || err_exit 'ksh plugin exit failed -- was ksh built with CCFLAGS+=$(CC.EXPORT.DYNAMIC)?'
if builtin getconf 2> /dev/null; then
$SHELL -c 'builtin -f cmd getconf; getconf --"?-version"; exit 0' >/dev/null 2>&1 || err_exit 'ksh plugin exit failed -- was ksh built with CCFLAGS+=$(CC.EXPORT.DYNAMIC)?'
fi
# ======
# Verify the 'exit' command behaves as expected

View file

@ -100,17 +100,19 @@ do ((x = x+1))
EOF
done
' 2> /dev/null || err_exit '100 empty here docs fails'
{
print 'builtin -d cat
cat <<- EOF'
for ((i=0; i < 100; i++))
do print XXXXXXXXXXXXXXXXXXXX
done
print ' XXX$(date)XXXX
EOF'
} > $f
chmod +x "$f"
$SHELL "$f" > /dev/null || err_exit "large here-doc with command substitution fails"
if (builtin cat) 2> /dev/null; then
{
print 'builtin -d cat
cat <<- EOF'
for ((i=0; i < 100; i++))
do print XXXXXXXXXXXXXXXXXXXX
done
print ' XXX$(date)XXXX
EOF'
} > $f
chmod +x "$f"
$SHELL "$f" > /dev/null || err_exit "large here-doc with command substitution fails"
fi
x=$("$bincat" <<!
$0
!
@ -138,35 +140,37 @@ abc
EOF) != $'#abc\nabc' ]]
then err_exit 'comments not preserved in here-documents'
fi
cat > "$f" <<- '!!!!'
builtin cat
: << EOF
$PWD
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
EOF
command exec 3>&- 4>&- 5>&- 6>&- 7>&- 8>&- 9>&-
x=abc
cat << EOF
$x
EOF
!!!!
chmod 755 "$f"
if [[ $($SHELL "$f") != abc ]]
then err_exit 'here document descriptor was closed'
fi
fi
cat > "$f" <<- '!!!!'
exec 0<&-

View file

@ -234,19 +234,21 @@ do exp=$1
shift 4
done
# setocale(LC_ALL,"") after setlocale() initialization
# setlocale(LC_ALL,"") after setlocale() initialization
printf 'f1\357\274\240f2\n' > input1
printf 't2\357\274\240f1\n' > input2
printf '\357\274\240\n' > delim
print "export LC_ALL=$locale
builtin cut || exit
cut -f 1 -d \$(cat delim) input1 input2 > out" > script
$SHELL -c 'unset LANG ${!LC_*}; $SHELL ./script' ||
err_exit "'cut' builtin failed -- exit code $?"
exp=$'f1\nt2'
got="$(<out)"
[[ $got == "$exp" ]] || err_exit "LC_ALL test script failed -- expected '$exp', got '$got'"
if builtin cut 2> /dev/null; then
printf 'f1\357\274\240f2\n' > input1
printf 't2\357\274\240f1\n' > input2
printf '\357\274\240\n' > delim
print "export LC_ALL=$locale
builtin cut
cut -f 1 -d \$(cat delim) input1 input2 > out" > script
$SHELL -c 'unset LANG ${!LC_*}; $SHELL ./script' || err_exit "'cut' builtin failed -- exit code $?"
exp=$'f1\nt2'
got="$(<out)"
[[ $got == "$exp" ]] || err_exit "LC_ALL test script failed" \
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
fi
# multibyte identifiers

View file

@ -288,7 +288,7 @@ typeset foo=$(PATH=/xyz:/abc :)
y=$(whence rm)
[[ $x != "$y" ]] && err_exit 'PATH not restored after command substitution'
whence getconf > /dev/null && err_exit 'getconf should not be found'
builtin /bin/getconf
builtin /bin/getconf 2> /dev/null
PATH=/bin
PATH=$(getconf PATH)
x=$(whence ls)
@ -309,11 +309,12 @@ status=$($SHELL -c $'trap \'print $?\' ERR;/dev/null 2> /dev/null')
# universe via PATH
builtin getconf
getconf UNIVERSE - att # override sticky default 'UNIVERSE = foo'
if builtin getconf 2> /dev/null; then
getconf UNIVERSE - att # override sticky default 'UNIVERSE = foo'
[[ $(PATH=/usr/ucb/bin:/usr/bin echo -n ucb) == 'ucb' ]] || err_exit "ucb universe echo ignores -n option"
[[ $(PATH=/usr/xpg/bin:/usr/bin echo -n att) == '-n att' ]] || err_exit "att universe echo does not ignore -n option"
[[ $(PATH=/usr/ucb/bin:/usr/bin echo -n ucb) == 'ucb' ]] || err_exit "ucb universe echo ignores -n option"
[[ $(PATH=/usr/xpg/bin:/usr/bin echo -n att) == '-n att' ]] || err_exit "att universe echo does not ignore -n option"
fi
PATH=$path
@ -435,7 +436,7 @@ x=$(whence -p echo 2> /dev/null)
[[ $x == "$tmp/new/bin/echo" ]] || err_exit 'nonexistent FPATH directory in .paths file causes path search to fail'
$SHELL 2> /dev/null <<- \EOF || err_exit 'path search problem with non-existent directories in PATH'
builtin getconf
builtin getconf 2> /dev/null
PATH=$(getconf PATH)
PATH=/dev/null/nogood1/bin:/dev/null/nogood2/bin:$PATH
tail /dev/null && tail /dev/null
@ -489,7 +490,7 @@ actual=$(set +x; PATH=$tmp; redirect 2>&1; hash ls; command -p ls /dev/null)
actual=$(set +x; PATH=$tmp; redirect 2>&1; hash ls; command -p ls /dev/null; exit) # the 'exit' disables subshell optimization
[[ $actual == "$expect" ]] || err_exit "'command -p' fails to search default path if tracked alias exists" \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
expect=$(builtin getconf; PATH=$(getconf PATH); whence -p ls)
expect=$(builtin getconf 2> /dev/null; PATH=$(getconf PATH); whence -p ls)
actual=$(set +x; PATH=$tmp; redirect 2>&1; hash ls; command -p -v ls)
[[ $actual == "$expect" ]] || err_exit "'command -p -v' fails to search default path if tracked alias exists" \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
@ -527,7 +528,8 @@ sleep_pid=$!
(
export LC_ALL=C
unset IFS; set +f
builtin getconf && arg_max=$(getconf ARG_MAX) && let arg_max || { err_exit "getconf ARG_MAX not working"; exit 1; }
builtin getconf 2> /dev/null
arg_max=$(getconf ARG_MAX) && let arg_max || { err_exit "getconf ARG_MAX not working"; exit 1; }
set +x # trust me, you don't want to xtrace what follows
# let's try to use a good variety of argument lengths
set -- $(typeset -p) $(functions) /dev/* /tmp/* /* *
@ -576,14 +578,16 @@ fi
# whence -a/-v tests
# wrong path to tracked aliases after loading builtin: https://github.com/ksh93/ksh/pull/25
actual=$("$SHELL" -c '
hash cat
builtin cat
whence -a cat
')
expect=$'cat is a shell builtin\n'$(all_paths cat | sed '1 s/^/cat is a tracked alias for /; 2,$ s/^/cat is /')
[[ $actual == "$expect" ]] || err_exit "'whence -a' does not work correctly with tracked aliases" \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
if (builtin cat) 2> /dev/null; then
actual=$("$SHELL" -c '
hash cat
builtin cat
whence -a cat
')
expect=$'cat is a shell builtin\n'$(all_paths cat | sed '1 s/^/cat is a tracked alias for /; 2,$ s/^/cat is /')
[[ $actual == "$expect" ]] || err_exit "'whence -a' does not work correctly with tracked aliases" \
"(expected $(printf %q "$expect"), got $(printf %q "$actual"))"
fi
# spurious 'undefined function' message: https://github.com/ksh93/ksh/issues/26
actual=$("$SHELL" -c 'whence -a printf')

View file

@ -23,7 +23,7 @@
typeset -F SECONDS # for fractional seconds in PS4
builtin getconf
builtin getconf 2> /dev/null
bincat=$(PATH=$(getconf PATH) whence -p cat)
binecho=$(PATH=$(getconf PATH) whence -p echo)
# make an external 'sleep' command that supports fractional seconds
@ -344,54 +344,54 @@ actual=$(
#
# the tests and timeouts are done in async subshells to prevent
# the test harness from hanging
if builtin cat 2> /dev/null; then
SUB=(
( BEG='$( ' END=' )' )
( BEG='${ ' END='; }' )
)
CAT=( cat $bincat )
INS=( "" "builtin cat; " "builtin -d cat $bincat; " ": > /dev/null; " )
APP=( "" "; :" )
TST=(
( CMD='print foo | $cat' EXP=3 )
( CMD='$cat < $tmp/lin' )
( CMD='cat $tmp/lin | $cat' )
( CMD='read v < $tmp/buf; print $v' LIM=4*1024 )
( CMD='cat $tmp/buf | read v; print $v' LIM=4*1024 )
)
SUB=(
( BEG='$( ' END=' )' )
( BEG='${ ' END='; }' )
)
CAT=( cat $bincat )
INS=( "" "builtin cat; " "builtin -d cat $bincat; " ": > /dev/null; " )
APP=( "" "; :" )
TST=(
( CMD='print foo | $cat' EXP=3 )
( CMD='$cat < $tmp/lin' )
( CMD='cat $tmp/lin | $cat' )
( CMD='read v < $tmp/buf; print $v' LIM=4*1024 )
( CMD='cat $tmp/buf | read v; print $v' LIM=4*1024 )
)
if cat /dev/fd/3 3</dev/null >/dev/null 2>&1 || whence mkfifo > /dev/null
then T=${#TST[@]}
TST[T].CMD='$cat <(print foo)'
TST[T].EXP=3
fi
if cat /dev/fd/3 3</dev/null >/dev/null 2>&1 || whence mkfifo > /dev/null
then T=${#TST[@]}
TST[T].CMD='$cat <(print foo)'
TST[T].EXP=3
fi
# prime the two data files to 512 bytes each
# $tmp/lin has newlines every 16 bytes and $tmp/buf has no newlines
# the outer loop doubles the file size at top
# prime the two data files to 512 bytes each
# $tmp/lin has newlines every 16 bytes and $tmp/buf has no newlines
# the outer loop doubles the file size at top
buf=$'1234567890abcdef'
lin=$'\n1234567890abcde'
for ((i=0; i<5; i++))
do buf=$buf$buf
lin=$lin$lin
done
print -n "$buf" > $tmp/buf
print -n "$lin" > $tmp/lin
buf=$'1234567890abcdef'
lin=$'\n1234567890abcde'
for ((i=0; i<5; i++))
do buf=$buf$buf
lin=$lin$lin
done
print -n "$buf" > $tmp/buf
print -n "$lin" > $tmp/lin
unset SKIP
for ((n=1024; n<=1024*1024; n*=2))
do cat $tmp/buf $tmp/buf > $tmp/tmp
mv $tmp/tmp $tmp/buf
cat $tmp/lin $tmp/lin > $tmp/tmp
mv $tmp/tmp $tmp/lin
for ((S=0; S<${#SUB[@]}; S++))
do for ((C=0; C<${#CAT[@]}; C++))
do cat=${CAT[C]}
for ((I=0; I<${#INS[@]}; I++))
do for ((A=0; A<${#APP[@]}; A++))
do for ((T=0; T<${#TST[@]}; T++))
do #undent...#
unset SKIP
for ((n=1024; n<=1024*1024; n*=2))
do cat $tmp/buf $tmp/buf > $tmp/tmp
mv $tmp/tmp $tmp/buf
cat $tmp/lin $tmp/lin > $tmp/tmp
mv $tmp/tmp $tmp/lin
for ((S=0; S<${#SUB[@]}; S++))
do for ((C=0; C<${#CAT[@]}; C++))
do cat=${CAT[C]}
for ((I=0; I<${#INS[@]}; I++))
do for ((A=0; A<${#APP[@]}; A++))
do for ((T=0; T<${#TST[@]}; T++))
do #undent...#
if [[ ! ${SKIP[S][C][I][A][T]} ]]
then eval "{ x=${SUB[S].BEG}${INS[I]}${TST[T].CMD}${APP[A]}${SUB[S].END}; print \${#x}; } >\$tmp/out &"
@ -423,13 +423,14 @@ do cat $tmp/buf $tmp/buf > $tmp/tmp
fi
fi
#...indent#
#...indent#
done
done
done
done
done
done
done
fi
# specifics -- there's more?
@ -606,7 +607,7 @@ trap ERR ERR
[[ $(trap -p) == *ERR* ]] || err_exit 'trap -p in subshell does not contain ERR'
trap - USR1 ERR
( builtin getconf && PATH=$(getconf PATH)
( builtin getconf 2> /dev/null && PATH=$(getconf PATH)
dot=$(cat <<-EOF
$(ls -d .)
EOF