Content of a file named file
testing 1
testing 2
Command tested
exec 3<> ./tmp
cat file 1>&3 3>&1
Outputs nothing. Why?
I read my command as
cat
content in file
, then read STDOUT
and give it to file descriptor 3
and then take the content from file descriptor 3
and give it's content to STDOUT
Am I reading my command wrong ?
How shall I read my command in order to understand it better and get the output of file
After understanding your answer Stéphane, I tried the following commands
cat file 1>&3 3> ofile
which didn't write the contents of fd 3 (which gets it's content from fd 1 i.e STDOUT) to ofile
but the I tried the following command
cat file 1>&3 && cat <3
which printed the content of fd 3 to the STDOUT.
Why didn't fd 3 write to ofile
when fd 3 has the content of fd 1 ?
Stéphane, the command Jesse_b mentioned in the comments below i.e
cat file 3> ofile 1>&3
works and does write the content of file
to ofile
but the command
cat file 1>&3 3> ofile
as I mentioned earlier fails to write to ofile
.
How did the placement of 1>&3
at the end and at the beginning of 3> ofile
affect the output of these two commands ?
file
toSTDOUT
you can execute this command:cat file
If you want to redirectSTDOUT
to something else you can docat file >
orcat file 1>
– jesse_b Jul 28 '17 at 21:371>&3
you aren't saying "redirect 1 to 3" you are saying "redirect 1 and 3" – jesse_b Jul 28 '17 at 21:38cat file 3> ofile 1>&3
also I don't think your second command is actually working. I think it's executing:cat file
and throwing away1>&3 && cat <3
– jesse_b Jul 28 '17 at 22:35command > /dev/null 2>&1
– jesse_b Jul 29 '17 at 1:31