July 18th, 2012, 12:46 AM
KSH error redirection
I am using a Linux variant by the name of OpenSUSE
anyways, this is actually for school and im really confused by a lab question i am dealing with. Perhaps someone can help me and educate me in the process. and ps this is in ksh
Q. Enter the following command: badcommand > outfile 2>&1 ; ls > outfile 2>&1.
View the outfile file. Why isn’t the error output from the “badcommand” command in the outfile?
ksh: badcommand: not found [No such file or directory] .
How would you change the previous command to get BOTH the badcommand error output AND the ls output to the outfile file? Enter the command here after you have verified that it works:
this is where i am a little confused, what is happening is that im able to redirect the ls information to outfile, but i repeatedly have issues with badcommand not found etc.
And hints or tips? stumped here.
July 18th, 2012, 01:24 AM
Well before anyone could reply I realized the solution was to go
badcommand >> outfile 2>&1 ; ls >> outfile 2>&1
So simple, glad i figured it out on my own however.
July 18th, 2012, 06:28 AM
Well done for working it out yourself.
One thing, you don't really need the append (>>) file redirection on the first command, unless you wish to preserve previous output to that particular logfile (outfile).
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc