Thursday 10 January 2013

Redirection on CLI: greater-thans, ampersands and numbers

  1. myCLIapp > /dev/null 2>&1
    1. Order is important, don't reverse the redirects
      1. See below
    2. First redirect sends STDOUT to kernel's blackhole equivalent
      1. result:  STDOUT is forgotten, never shown
      2. STDOUT is implied when no number before '>'
    3. Second redirect sends STDERR to where STDOUT points
      1. STDERR goes where STDOUT goes
      2. So STDERR ends up in blackhole too
      3. The amphersand is necessary
        1. to specify this is a "file handle" 
        2. and not a filename
  2. Reverse mistake
    1. myCLIapp 2>&1 > /dev/null 
      1. Read left to right
      2. 2>&1
        1. Would 1st send STDERR to where STDOUT is pointing currently
          1. Which is STDOUT so far
      3. > /dev/null
        1. STDOUT is implied since no number before '>'
        2. Send STDOUT to /dev/null
      4. Result is
        1. STDERR being displayed
        2. STDOUT being sent to blackhole
  3. Remember
    1. if no number given before '>', them implied is STDOUT
http://www.tldp.org/LDP/abs/html/io-redirection.html

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

Interview questions: 2020-12

Terraform provider vs provisioner Load balancing Network Load Balancer vs Application Load Balancer  Networking Layer 1 vs Layer 4 haproxy u...