fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
9ea760c40
master
1#RUN: %fish %s 2 3function outnerr 4command echo out$argv 5command echo err$argv 1>&2 6end 7 8outnerr 0 &| count 9#CHECK: 2 10 11outnerr 1 |& count 12#CHECK: 2 13 14 15outnerr appendfd2>>&1 16#CHECK: out appendfd 17#CHECK: err appendfd 18 19set -l tmpdir( mktemp -d) 20outnerr overwrite&> $tmpdir /file.txt 21cat $tmpdir /file.txt 22#CHECK: out overwrite 23#CHECK: err overwrite 24 25outnerr append&>> $tmpdir /file.txt 26cat $tmpdir /file.txt 27#CHECK: out overwrite 28#CHECK: err overwrite 29#CHECK: out append 30#CHECK: err append 31 32echo noclobber&>>? $tmpdir /file.txt 33#CHECKERR: {{.*}} The file {{.*}} already exists 34 35# Ensure that redirection empty data still creates the file. 36rm -f$tmpdir /file.txt 37test -f $tmpdir /file.txt&& echo "File exists" || echo "File does not exist" 38#CHECK: File does not exist 39 40echo -n> $tmpdir /file.txt 41test -f $tmpdir /file.txt&& echo "File exists" || echo "File does not exist" 42#CHECK: File exists 43 44rm $tmpdir /file.txt 45echo -n2> $tmpdir /file.txt 46test -f $tmpdir /file.txt&& echo "File exists" || echo "File does not exist" 47#CHECK: File exists 48 49rm $tmpdir /file.txt 50 51function redir_to_argv1 52if set -q argv[ 1 ] 53redir_to_argv1 > $argv [ 1 ] 54end 55echo foo 56end 57 58redir_to_argv1 $tmpdir /bar 59# CHECK: foo 60cat $tmpdir /bar 61# CHECK: foo 62rm $tmpdir /bar 63 64# Verify that we can turn stderr into stdout and then pipe it 65# Note that the order here has historically been unspecified - 'errput' could conceivably appear before 'output'. 66begin 67echo output 68echo errput1>&2 69end 2>&1 | sort | tee $tmpdir /tee_test.txt 70cat $tmpdir /tee_test.txt 71 72rm $tmpdir /tee_test.txt 73rmdir $tmpdir 74 75#CHECK: errput 76#CHECK: output 77#CHECK: errput 78#CHECK: output 79 80# Test that trailing ^ doesn't trigger redirection, see #1873 81echo caret_no_redirect 12345^ 82#CHECK: caret_no_redirect 12345^ 83 84# Verify that we can pipe something other than stdout 85# The first line should be printed, since we output to stdout but pipe stderr to /dev/null 86# The second line should not be printed, since we output to stderr and pipe it to /dev/null 87begin 88echo is_stdout 89end 2>| cat > /dev/null 90begin 91echo is_stderr1>&2 92end 2>| cat > /dev/null 93#CHECK: is_stdout 94 95# Verify builtin behavior with closed stdin. 96# count silently ignores closed stdin, others may print an error. 97true <&- 98echo $status 99#CHECK: 0 100test -t 0 <&- 101echo $status 102#CHECK: 1 103read abc<&- 104#CHECKERR: read: stdin is closed 105 106# This one should output nothing. 107echo derp>&- 108 109# Redirection to 0, 1, 2 should always work. We don't test 0 since writing to stdin is weird and unpredictable. 110echo hooray1>&1 111echo hooray2>&2 112#CHECK: hooray1 113#CHECKERR: hooray2 114 115# "Verify that pipes don't conflict with fd redirections" 116# This code is very similar to eval. We go over a bunch of fads 117# to make it likely that we will nominally conflict with a pipe 118# fish is supposed to detect this case and dup the pipe to something else 119echo "command echo pipe 3 <&3 3<&-" | source 3<&0 120echo "command echo pipe 4 <&4 4<&-" | source 4<&0 121echo "command echo pipe 5 <&5 5<&-" | source 5<&0 122echo "command echo pipe 6 <&6 6<&-" | source 6<&0 123echo "command echo pipe 7 <&7 7<&-" | source 7<&0 124echo "command echo pipe 8 <&8 8<&-" | source 8<&0 125echo "command echo pipe 9 <&9 9<&-" | source 9<&0 126echo "command echo pipe 10 <&10 10<&-" | source 10<&0 127echo "command echo pipe 11 <&11 11<&-" | source 11<&0 128echo "command echo pipe 12 <&12 12<&-" | source 12<&0 129#CHECK: pipe 3 130#CHECK: pipe 4 131#CHECK: pipe 5 132#CHECK: pipe 6 133#CHECK: pipe 7 134#CHECK: pipe 8 135#CHECK: pipe 9 136#CHECK: pipe 10 137#CHECK: pipe 11 138#CHECK: pipe 12 139 140echo foo> /bin/sh/file 141#CHECKERR: warning: An error occurred while redirecting file '/bin/sh/file' 142#CHECKERR: warning: Path '/bin/sh' is not a directory 143 144echo foo< ?nonexistent 145#CHECK: foo 146echo $status 147#CHECK: 0 148 149read -l foo< ?nonexistent 150echo $status 151#CHECK: 1 152set -S foo 153#CHECK: $foo: set in local scope, unexported, with 0 elements 154 155set -l fish( status fish-path) 156$fish --no-config -c'true <&?fail' 157#CHECKERR: fish: Requested redirection to '?fail', which is not a valid file descriptor 158#CHECKERR: true <&?fail 159#CHECKERR: ^~~~~~^ 160 161$fish --no-config -c'true <?&fail' 162#CHECKERR: fish: Expected a string, but found a '&' 163#CHECKERR: true <?&fail 164#CHECKERR: ^