Redirection and pipe bonzanza

Open a shell and create a new bash file in your favorite editor:

#!/bin/sh# Let's run a command and send all of the output to /dev/nullecho "No output?"ls ~/fakefile.txt > /dev/null 2>&1# Retrieve output from a piped command echo "part 1"HISTORY_TEXT=`cat ~/.bashrc | grep HIST`echo "${HISTORY_TEXT}"# Output the results to history.configecho "part 2"echo "${HISTORY_TEXT}" > "history.config"# Re-direct history.config as input to the cat commandcat < history.config# Append a string to history.configecho "MY_VAR=1" >> history.configecho "part 3 - using Tee"# Neato.txt will contain the same information as the consolels -la ~/fakefile.txt ~/ 2>&1 | tee neato.txt

First, ls is a way of producing an error and, instead ...

Get Bash Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.