Noob question!
I've got a function on the command line that takes parameters
sqr() { echo $(( $1 * $1 )) ; }
sqr 4 echos 16. fine.
Now I want to pipe an output to this function
echo 4 | sqr
I get " syntax error: operand expected (error token is "* ") " - clearly $1 is empty
I've tried using xargs with various options to pass the stdio to the function but I get "No such file or directory" errors. Am I missing something obvious?
One way could be using parameter expansion on
$1to havecatflush STDIN as fallback: