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


Popular posts from this blog

Openvpn and unbound combined break dig command

Stress Linux system: stress-ng

Google Nexus 4: permanent back panel glass repair for less than a penny