Skip to content

Instantly share code, notes, and snippets.

@nelaaro
Forked from miguelmota/pipe_tail_read_file.sh
Created October 18, 2023 07:31
Show Gist options
  • Save nelaaro/593bf8d705b82df0d066e4d7e6b5c1d2 to your computer and use it in GitHub Desktop.
Save nelaaro/593bf8d705b82df0d066e4d7e6b5c1d2 to your computer and use it in GitHub Desktop.
Bash pipe tail file while loop read line
#!/bin/bash
# read from stdin
while read line
do
echo "$line"
done < "${1:-/dev/stdin}"
# read from file
while read line
do
echo "$line"
done < <(tail -f data.txt)
# read from file also
tail -f data.txt | while read line
do
echo "$line"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment