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

    Join Date
    May 2012
    Posts
    14
    Rep Power
    0

    /dev/null not working


    Hi,

    I have a statement like this:

    COMMAND="which java"
    RUN_COMMAND=`eval "$COMMAND"` > /dev/null
    echo "Output of the command:"$RUN_COMMAND


    Here if java doesn't exist in the system it throws some output like
    no java in (/usr/local/bin:/usr/bin
    And I don't want this to be on the console.
    So, even after redirecting the output to /dev/null it's still sending the output to the console.
    Any idea?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    14
    Rep Power
    0
    Well I got the answer...

    COMMAND="which java"
    RUN_COMMAND=`eval "$COMMAND"" 2> /dev/null"`
    echo "Output of the command:"$RUN_COMMAND
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Posts
    11
    Rep Power
    0
    Yes, the "2>" directs stderr to /dev/null where ">" redirects standard output.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,436
    Rep Power
    1688
    Originally Posted by Squ3lch
    Yes, the "2>" directs stderr to /dev/null where ">" redirects standard output.
    More to the point, the redirection was moved to within the command ticks. Where it was in the original only related to the variable setting command, not the running of the command. The change to stderr (file 2) is what made the error message be thrown to the bit bucket.
    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