mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-12-13 09:24:03 +08:00
97dd5ece26
This was previously required so that, if there was a redirection to a file, we would fork a process to create the file even if there was no output. For example `echo -n >/tmp/file.txt` would have to create file.txt even though it would be empty. However now we open the file before fork, so we no longer need special logic around this.
47 lines
1.1 KiB
Fish
47 lines
1.1 KiB
Fish
#RUN: %fish %s
|
|
|
|
function outnerr
|
|
command echo out $argv
|
|
command echo err $argv 1>&2
|
|
end
|
|
|
|
outnerr 0 &| count
|
|
#CHECK: 2
|
|
|
|
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
|