Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
Redirection mystery
Results 1 to 6 of 6

Thread: Redirection mystery

  1. #1

    Redirection mystery

    Why does the following simple command at the bash shell not redirect the permission denied messages?
    Code:
    $ ls -R /etc |grep 'resolve.conf' 2>/dev/null
    ls: /etc/audisp: Permission denied
    ls: /etc/audit: Permission denied
    ls: /etc/cron.d: Permission denied
    ls: /etc/cups/ssl: Permission denied
    ls: /etc/lvm/archive: Permission denied
    ls: /etc/lvm/backup: Permission denied
    ls: /etc/lvm/cache: Permission denied
    ls: /etc/pki/CA: Permission denied
    ls: /etc/racoon/certs: Permission denied
    ls: /etc/selinux/targeted/modules/active: Permission denied
    ls: /etc/selinux/targeted/modules/previous: Permission denied
    resolv.conf
    resolv.conf.predhclient
    A similar command using find does redirect the permission denied messages as expected:
    Code:
    $ find /etc -name 'resolv.conf' -print 2>/dev/null
    /etc/resolv.conf

  2. #2
    Administrator Advisor peter's Avatar
    Join Date
    Apr 2004
    Posts
    882
    Hello!

    Your redirection is at the wrong place. Also you are grepping for "resolve.conf" not "resolv.conf"

    Code:
    # ls -R /etc 2>/dev/null | grep resolv.conf

    My sites:
    To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
    -
    To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

  3. #3
    Yes, you are correct. I asked this same question to some of my students and none of them could figure this out. I was being a little sneaky with this as I already knew the answer. I just wondered if anyone had a clue. Thank you for your response.

    There are a couple of clues as to why this doesn't work. Look at the output of the first command. Clearly the errors are comming from the ls command and not the grep command as evidenced by the leading ls: part of the errors. Also if the first command is followed up with a 'echo $?' it returns an exit status of zero. So the errors did not come from the right side of the pipe or the last command in the chain.

    Finally, the bash man page clearly makes a big deal out of how important the order is when dealing with redirection. But I can't get anybody to read the man page.

  4. #4
    Administrator Advisor peter's Avatar
    Join Date
    Apr 2004
    Posts
    882
    I'm glad I passed that test. Phew! Invite your students to check out the little community we have here.

    My sites:
    To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
    -
    To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

  5. #5
    I'll definitely point out the resource to them but it's going to be an uphill battle for sure.

  6. #6
    Associate
    Join Date
    Nov 2008
    Location
    Live in Fayetteville, PA and work in Washington, DC.
    Posts
    13
    you can lead a hourse to water....

Similar Threads

  1. Redirection of openfree.org
    By mechdave in forum General Chat
    Replies: 1
    Last Post: 10-22-2008, 01:32 PM
  2. ZEN mystery
    By toastrack in forum Suse
    Replies: 2
    Last Post: 01-07-2008, 09:28 AM
  3. Mass redirection problem
    By morphman in forum Linux - Software, Applications & Programming
    Replies: 5
    Last Post: 06-14-2002, 02:38 PM
  4. Murder Mystery
    By dalee in forum Linux - General Topics
    Replies: 6
    Last Post: 01-13-2002, 08:50 PM
  5. An original mystery
    By ndogg in forum General Chat
    Replies: 21
    Last Post: 11-25-2001, 06:41 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •