fish-shell/tests/checks/redirect.fish
Fabian Homborg 2af174513e Reallow "2>>&1" as a redirection
Appending to an fd doesn't really make sense, but we allowed the
syntax previously and it was actually used.

It's not too harmful to allow it, so let's just do that again.

For the record: Zsh also allows it, bash doesn't.

Fixes #6614

(cherry picked from commit aba900a71f)
2020-02-22 23:33:30 +08:00

52 lines
1.2 KiB
Fish

#RUN: %fish %s
function outnerr
command echo out $argv
command echo err $argv 1>&2
end
outnerr 0 &| count
#CHECK: 2
outnerr appendfd 2>>&1
#CHECK: out appendfd
#CHECK: err appendfd
set -l tmpdir (mktemp -d)
outnerr overwrite &>$tmpdir/file.txt
cat $tmpdir/file.txt
#CHECK: out overwrite
#CHECK: err overwrite
outnerr append &>>$tmpdir/file.txt
cat $tmpdir/file.txt
#CHECK: out overwrite
#CHECK: err overwrite
#CHECK: out append
#CHECK: err append
echo noclobber &>>?$tmpdir/file.txt
#CHECKERR: {{.*}} The file {{.*}} already exists
eval "echo foo |& false"
#CHECKERR: {{.*}} |& is not valid. In fish, use &| to pipe both stdout and stderr.
#CHECKERR: echo foo |& false
#CHECKERR: ^
# Ensure that redirection empty data still creates the file.
rm -f $tmpdir/file.txt
test -f $tmpdir/file.txt && echo "File exists" || echo "File does not exist"
#CHECK: File does not exist
echo -n >$tmpdir/file.txt
test -f $tmpdir/file.txt && echo "File exists" || echo "File does not exist"
#CHECK: File exists
rm $tmpdir/file.txt
echo -n 2>$tmpdir/file.txt
test -f $tmpdir/file.txt && echo "File exists" || echo "File does not exist"
#CHECK: File exists
rm -Rf $tmpdir