Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Created August 2, 2018 06:17
Show Gist options
  • Save miguelmota/5417fad9c1162ad0c4fa2a5e6e134457 to your computer and use it in GitHub Desktop.
Save miguelmota/5417fad9c1162ad0c4fa2a5e6e134457 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