metalx1000

Working with Standard Error and Output in BASH Linux shell

May 19th, 2017
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.61 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. echo "This is standard output"
  4.  
  5. echo "This is an error" >&2
  6.  
  7. #as a function
  8. echoerr() {
  9.   echo "$@" 1>&2;
  10. }
  11.  
  12. echoerr "This is another error"
  13.  
  14. echo "this is more standard output"
  15.  
  16. echo "You can also use /dev/stderr for standard error output" >>/dev/stderr
  17.  
  18. ###view only the standard out
  19. #./stio.sh 1> /dev/null
  20. ###This will save standard output and display only standard error
  21. #./stio.sh > test.log
  22. ###IF you want to save both standard output and error
  23. #./stio.sh > output.txt 2>&1
  24.  
  25. ###Another example
  26. #find / -name "test.png" > output.txt 2>&1
  27. #find / -name "test.png" 2>/dev/null
Add Comment
Please, Sign In to add comment