Last active
December 14, 2020 02:39
-
-
Save jeremyckahn/01d74a0051e6d943597fa5b751a37403 to your computer and use it in GitHub Desktop.
Demo of reading stdin to a BASH script variable
This file contains hidden or 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
#!/bin/bash | |
# Usage: | |
# echo 'hello!' | ./read-stdin-to-variable.sh | |
# https://stackoverflow.com/a/15269128 | |
STD_IN=$(</dev/stdin) | |
echo "Echoing stdin:" | |
echo "$STD_IN" | |
echo "Echoing again:" | |
echo "$STD_IN" |
This file contains hidden or 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
#!/bin/bash | |
STD_IN=$(</dev/stdin) | |
echo $STD_IN | sed 's/-/_/g' |
This file contains hidden or 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
#!/bin/bash | |
STD_IN=$(</dev/stdin) | |
# https://stackoverflow.com/a/27480719 | |
echo $STD_IN | awk '{print toupper($0)}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment