#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0

    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?

    My answer
    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.
    .
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0
    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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,448
    Rep Power
    1751
    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

IMN logo majestic logo threadwatch logo seochat tools logo