" /> bash - Dans le coquillage, ce que signifie " 2 signes" | 2022 codeprofesseur

bash - Dans le coquillage, ce que signifie " 2 signes"

Mots clés : bashshellunixredirectbashbashbash

meilleur 3 Réponses bash - Dans le coquillage, ce que signifie " 2 signes"

vote vote

98

echo test > afile.txt 
echo test 1> afile.txt 
echo test 2> afile.txt 
echo test 1>&2 # or echo test >&2 
echo test 2>&1 
vote vote

82

$ ls -ld /tmp /tnt ls: cannot access /tnt: No such file or directory drwxrwxrwt 118 root root 196608 Jan  7 11:49 /tmp  $ ls -ld /tmp /tnt >/dev/null ls: cannot access /tnt: No such file or directory  $ ls -ld /tmp /tnt 2>/dev/null drwxrwxrwt 118 root root 196608 Jan  7 11:49 /tmp 
$ ls -ld /tmp /tnt >/dev/null ls: cannot access /tnt: No such file or directory  $ ls -ld /tmp /tnt >/dev/null 2>&1  $ ls -ld /tmp /tnt 2>&1 >/dev/null ls: cannot access /tnt: No such file or directory 
$ ls -ld /tmp /tnt | sed 's/^.*$/<-- & --->/' ls: cannot access /tnt: No such file or directory <-- drwxrwxrwt 118 root root 196608 Jan  7 12:02 /tmp --->  $ ls -ld /tmp /tnt 2>&1 | sed 's/^.*$/<-- & --->/' <-- ls: cannot access /tnt: No such file or directory ---> <-- drwxrwxrwt 118 root root 196608 Jan  7 12:02 /tmp --->  $ ls -ld /tmp /tnt >/dev/null | sed 's/^.*$/<-- & --->/' ls: cannot access /tnt: No such file or directory  $ ls -ld /tmp /tnt >/dev/null 2>&1 | sed 's/^.*$/<-- & --->/'  $ ls -ld /tmp /tnt 2>&1 >/dev/null | sed 's/^.*$/<-- & --->/' <-- ls: cannot access /tnt: No such file or directory ---> 
$ ( ls -ld /tmp /tnt | sed 's/^/O: /' >&9 ) 9>&2  2>&1  | sed 's/^/E: /' O: drwxrwxrwt 118 root root 196608 Jan  7 12:13 /tmp E: ls: cannot access /tnt: No such file or directory 
$ ls -ld /tmp /tnt 2> >(sed 's/^/E: /') > >(sed 's/^/O: /') O: drwxrwxrwt 17 root root 28672 Nov  5 23:00 /tmp E: ls: cannot access /tnt: No such file or directory 
$ ((ls -ld /tmp /tnt |sed 's/^/O: /' >&9 ) 2>&1 |sed 's/^/E: /') 9>&1| cat -n      1  O: drwxrwxrwt 118 root root 196608 Jan  7 12:29 /tmp      2  E: ls: cannot access /tnt: No such file or directory 
$ cat -n <(ls -ld /tmp /tnt 2> >(sed 's/^/E: /') > >(sed 's/^/O: /'))      1  O: drwxrwxrwt 17 root root 28672 Nov  5 23:00 /tmp      2  E: ls: cannot access /tnt: No such file or directory 
$ testfile=$(mktemp /tmp/testNoClobberDate-XXXXXX)  $ date > $testfile ; cat $testfile Mon Jan  7 13:18:15 CET 2013  $ date > $testfile ; cat $testfile Mon Jan  7 13:18:19 CET 2013  $ date > $testfile ; cat $testfile Mon Jan  7 13:18:21 CET 2013 
$ set -o noclobber  $ date > $testfile ; cat $testfile bash: /tmp/testNoClobberDate-WW1xi9: cannot overwrite existing file Mon Jan  7 13:18:21 CET 2013  $ date > $testfile ; cat $testfile bash: /tmp/testNoClobberDate-WW1xi9: cannot overwrite existing file Mon Jan  7 13:18:21 CET 2013 
$ date >| $testfile ; cat $testfile Mon Jan  7 13:18:58 CET 2013  $ date >| $testfile ; cat $testfile Mon Jan  7 13:19:01 CET 2013 
$ set -o | grep noclobber noclobber           on  $ set +o noclobber  $ set -o | grep noclobber noclobber           off  $ date > $testfile ; cat $testfile Mon Jan  7 13:24:27 CET 2013  $ rm $testfile 
$ ls -ld /tmp /tnt >/dev/null 2>&1 
$ ls -ld /tmp /tnt &>/dev/null  $ ls -ld /tmp /tnt >&/dev/null 
$ ls -ld /tmp /tnt 2>/dev/null 1>&2 
$ ls -ld /tmp /tnt 2>&1 1>&2  | sed -e s/^/++/ ++/bin/ls: cannot access /tnt: No such file or directory ++drwxrwxrwt 193 root root 196608 Feb  9 11:08 /tmp/  $ ls -ld /tmp /tnt 1>&2 2>&1  | sed -e s/^/++/ /bin/ls: cannot access /tnt: No such file or directory drwxrwxrwt 193 root root 196608 Feb  9 11:08 /tmp/ 
man -Len -Pless\ +/^REDIRECTION bash 
vote vote

76

/* Standard file descriptors.  */ #define STDIN_FILENO    0   /* Standard input.  */ #define STDOUT_FILENO   1   /* Standard output.  */ #define STDERR_FILENO   2   /* Standard error output.  */ 

Questions similaires