Pipes and Redirects in Scripts

View saved

Pipes

Send stdout of one command to stdin of the next.

grep error app.log | sort | uniq -c

Redirects

Send output to files; append with >>.

echo "ok" > result.txt
echo "more" >> result.txt
cmd 2> errors.txt
cmd >all.txt 2>&1

Here-documents

Feed multi-line input without temp files.

cat <<EOF > config.env
NAME=demo
MODE=dev
EOF

Quiet and loud modes

Redirect noisy commands when appropriate, but keep failures visible—especially under set -e.

if mkdir -p "$dir" 2>/dev/null; then
  echo "ready: $dir"
fi

Comments

One comment per signed-in account. Comments are saved with this page’s URL.