Poop Sheet

Redirection

Redirection

What is a File descriptor?

#!/usr/bin/bash

ExampleGroup 'Redirection'

  fd2() { echo "err" >&2; }

  Example 'Standard input (stdin) is file descriptor 0'
    When call ls -l /dev/stdin
    The path /dev/stdin should be symlink
    The word 11 of stdout should eq "/proc/self/fd/0"
    The output should include "/proc/self/fd/0"
  End

  Example 'Standard output (stdout) is file descriptor 1'
    When call ls -l /dev/stdout
    The path /dev/stdin should be symlink
    The word 11 of stdout should eq "/proc/self/fd/1"
    The output should include "/proc/self/fd/1"
  End

  Example 'Standard error (stderr) is file descriptor 2'
    When call ls -l /dev/stderr
    The path /dev/stdin should be symlink
    The word 11 of stdout should eq "/proc/self/fd/2"
    The output should include "/proc/self/fd/2"
  End

  Example 'uses the stderr as the subject'
    When call fd2
    The stderr should eq "err"
  End

  Example 'has an alias "error"'
    When call fd2
    The error should eq "err"
  End

  Example 'ls error from missing file'
    When call ls -l spec/examples_spec.sh 'not-here.txt'
    The output should include "spec/examples_spec.sh"
    The status should be failure
    The stderr should eq "ls: cannot access 'not-here.txt': No such file or directory"
  End

End