Redirection connects command output and input to files. Scripts use it for temporary data, reports, and logs.

Program

Play the script to watch text move into a file and a line count come back out.

redirects.sh
#!/usr/bin/env bash

file="$(mktemp)"
printf 'alpha\nbeta\n' > "$file"
lines="$(wc -l < "$file")"
rm "$file"
echo "lines=$lines"
redirection `>` writes stdout to a file and `<` reads stdin from a file.
temporary file `mktemp` creates a unique path for short-lived script data.