Pipe Arguments To Bash Function
This article was last edited over 3 years ago. Information here may no longer be accurate. Please proceed with caution, and feel free to contact me.
This is a trivial example, but is meant to demonstrate how you can pipe arguments to a bash function.
#!/usr/bin/env bash
lowercase()
{
# Grab input.
declare input=${1:-$(</dev/stdin)};
# Use that input to do anything.
echo "$input" | tr '[:upper:]' '[:lower:]'
}
echo "HELLO there, FRIEND!" | lowercase
Which outputs the following.
hello there, friend!
Feel free to contact me with questions or feedback regarding this
article.