so for a question I have to store both messages of x and y to log, since y only exists and x does not I used cat x y &> log to be able to store both messages. However as the second part my professor wants us to use tee to store both messages and output both messages on the screen, i have tried things like cat x y &> log | tee log ,,, tee x y &> log ,,, log | x y &> log | tee log but can't seem to get it to work at all, I even google search how and have absolute no clue, anyone have anything that could help?
Asked
Active
Viewed 329 times
0
Phantom1421
- 71
1 Answers
1
If I understand your comments correctly, you have something like the following scenario:
- file
ycontains some text - file
xdoesn't exist - file
logdoesn't exist (or you don't care if you delete its contents with the command I give you).
You want to have the error message about the nonexistence of file x and the contents of file y both dumped into the file log, and you also want this output displayed on your terminal.
If that's all correct, what you want is:
cat x y 2>&1 | tee log
(NOTE: If this doesn't do what you want, edit your question to include the actual error message you got, and explain clearly how it is different from the result you wanted.)
Wildcard
- 36,499
-
my apologies i made mistake that earlier comment on
cat x y | tee logworked fine i found the problem on why it didn't, sorry and thanks for the help. you can edit answer so it looks like that. – Phantom1421 Mar 30 '16 at 02:13 -
@Phantom1421 the earlier command
cat x y | tee logwill not put the error message fromcatinto the filelog. The command in my answer will. – Wildcard Mar 30 '16 at 04:57
teeis a command;&>and|are both redirection operators.teenever sees the output ofcatin this case, because you already redirected the output ofcatto a file. Trycat x y | tee log– Wildcard Mar 30 '16 at 01:02xand you don't have anything in fileythen of course you don't see anything. Perhaps you meant to useechoinstead ofcat. – Wildcard Mar 30 '16 at 01:07&>is not a standard redirection operator, by the way, it is specific tobash.) Anyway&> filenamemeans the same thing (inbash) as2>&1 > filenamemeans in any shell. What you want to do instead is redirect stderr to the same place as stdout, then pipe stdout intotee. Read the post I linked. – Wildcard Mar 30 '16 at 01:13cat x y | tee logworked fine i found the problem on why it didn't, sorry and thanks for the help. – Phantom1421 Mar 30 '16 at 02:12&> filenamemeans the same thing (inbash) as> filename 2>&1(or2> filename >&2) *but not*2>&1 > filename— that’s different; order matters (and can sometimes be difficult to understand). – G-Man Says 'Reinstate Monica' Aug 10 '16 at 01:35