Do shell expansion for output lines (|, @ and ?), so that it is possible to evaluate arbitrary shell expressions. Other fixes included: - Don't assume ksh is in bin. - Eval commands using the standard shell instead of ksh. - Make sure we delete temp files; also avoid creating a temp file per line. - Don't print ? output if return status is 0. - Fix literal \? match when evaluating lines.
76 lines
899 B
Bash
Executable File
76 lines
899 B
Bash
Executable File
#!/usr/bin/env ksh
|
|
|
|
function tsrun
|
|
{
|
|
typeset ret
|
|
|
|
sh -c "$@" >$out 2>$err
|
|
ret=$?
|
|
sed 's/^/| /' $out
|
|
sed 's/^/@ /' $err
|
|
(( ret != 0 )) && print "? $ret"
|
|
}
|
|
|
|
function tseval
|
|
{
|
|
typeset ln
|
|
|
|
while read ln
|
|
do
|
|
case ${ln%% *} in
|
|
$)
|
|
print "$ln"
|
|
tsrun "${ln#$}"
|
|
;;
|
|
!(\?|@|\|))
|
|
print "$ln"
|
|
;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
function tsexpand
|
|
{
|
|
typeset ln
|
|
|
|
while read ln
|
|
do
|
|
case ${ln%% *}
|
|
in
|
|
\?|@|\|)
|
|
eval print \""$ln"\"
|
|
;;
|
|
*)
|
|
print "$ln"
|
|
;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
(( $# == 0 )) && exit 64
|
|
|
|
err=$(mktemp /tmp/XXXXXXXXXX)
|
|
out=$(mktemp /tmp/XXXXXXXXXX)
|
|
trap "rm $err $out" HUP INT QUIT TERM
|
|
|
|
if [[ $1 = -b ]]
|
|
then
|
|
(( $# == 1 )) && exit 64
|
|
shift
|
|
for fn
|
|
do
|
|
cp $fn $fn~
|
|
(rm $fn && tseval >$fn) <$fn
|
|
done
|
|
else
|
|
exp=$(mktemp /tmp/XXXXXXXXXX)
|
|
trap "rm $exp" HUP INT QUIT TERM
|
|
for fn
|
|
do
|
|
tsexpand <$fn >$exp
|
|
tseval <$fn | diff -u $exp -
|
|
done
|
|
rm $exp
|
|
fi
|
|
rm $err $out
|