Created
September 22, 2021 00:45
-
-
Save ezr/bb651927739abe41d0bd59bb8c031ee0 to your computer and use it in GitHub Desktop.
Print the supplied format once for each line of stdin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
USAGE=$(cat <<-END | |
Error: no argument supplied. | |
This program prints the template once for each line of stdin. It only substitutes one variable in the printf format string. | |
Usage: | |
$0 <printf_format> < data | |
Examples: | |
$0 'ping -c 1 %s' < hosts | |
END | |
) | |
if [ -z "$1" ]; then | |
printf "$USAGE\n" "%s" | |
exit 1 | |
fi | |
while read line; do | |
printf "$1\n" "$line" | |
done < /dev/stdin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment