Skip to content

Instantly share code, notes, and snippets.

@jeremyckahn
Last active December 14, 2020 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyckahn/01d74a0051e6d943597fa5b751a37403 to your computer and use it in GitHub Desktop.
Save jeremyckahn/01d74a0051e6d943597fa5b751a37403 to your computer and use it in GitHub Desktop.
Demo of reading stdin to a BASH script variable
#!/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"
#!/bin/bash
STD_IN=$(</dev/stdin)
echo $STD_IN | sed 's/-/_/g'
#!/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