+run_sbcl --script $tmpscript >/dev/null
+check_status_maybe_lose "--script exit status from QUIT when original standard-output closed" $? 3 "(as given)"
+run_sbcl --load $tmpscript >/dev/null
+check_status_maybe_lose "--load exit status from QUIT when original standard-output closed" $? 3 "(as given)"
+
+cat > $tmpscript <<EOF
+(close sb-sys:*stdout*)
+(sb-ext:quit :unix-status 3)
+EOF
+run_sbcl --script $tmpscript >/dev/null
+check_status_maybe_lose "--script exit status from EXIT when stdout closed" $? 3 "(as given)"
+run_sbcl --load $tmpscript >/dev/null
+check_status_maybe_lose "--load exit status from EXIT when stdout closed" $? 3 "(as given)"
+
+cat > $tmpscript <<EOF
+(loop (write-line (read-line)))
+EOF
+echo ONE | run_sbcl --script $tmpscript 1> $tmpout 2> $tmperr
+check_status_maybe_lose "--script exit status when stdin closed" $? 0 "(as given)"
+if [ -s $tmperr ] || [ "ONE" != `cat $tmpout` ]
+then
+ echo "--script outputs wrong"
+ exit $EXIT_LOSE
+fi
+
+cat > $tmpscript <<EOF
+(loop (write-line "foo"))
+EOF
+run_sbcl --script $tmpscript 2> $tmperr | head -n1 > $tmpout
+check_status_maybe_lose "--script exit status when stdout closed" $? 0 "(as given)"
+if [ -s $tmperr ] || [ "foo" != `cat $tmpout` ]
+then
+ echo "--script unexpected error output"
+ exit $EXIT_LOSE
+fi
+echo '(write-line "Ok!")' | run_sbcl --script 1>$tmpout 2>$tmperr
+check_status_maybe_lose "--script exit status from stdin" $? 0 "(ok)"
+if [ -s $tmperr ] || [ "Ok!" != `cat $tmpout` ]
+then
+ echo "--script unexpected error output"
+ exit $EXIT_LOSE
+fi
+
+# --script
+cat > $tmpscript <<EOF
+(print :script-ok)
+EOF
+run_sbcl --script $tmpscript --eval foo \
+ < /dev/null > $tmpout
+if [ "`grep -c :SCRIPT-OK $tmpout`" != 1 ] ; then
+ echo "failed --script test using PRINT"
+ exit $EXIT_LOSE
+fi
+
+# automatically executing fasls
+#
+# this test is fragile, with its SBCL_HOME hack to get the shebang
+# line in the fasl to find the right core, and also is unlikely to
+# work with that mechanism on Windows.
+echo '(format t "Hello, Fasl~%")' > $tmpscript
+run_sbcl --eval "(compile-file \"$tmpscript\" :output-file \"$tmpfasl\")" </dev/null >/dev/null
+chmod +x $tmpfasl
+SBCL_HOME=$(dirname $SBCL_CORE) ./$tmpfasl >$tmpout 2>$tmperr
+check_status_maybe_lose "--script exit status from fasl" $? 0 "(ok)"
+if [ -s $tmperr ] || [ "Hello, Fasl" != "`cat $tmpout`" ]
+then
+ echo "--script from fasl unexpected output"
+ exit $EXIT_LOSE
+fi