1

So I am trying to echo a string out to a log file and also pass that echo'd string over to a function along with other arguments as well. I can't seem to figure out how to do it or find any answers on here. Here is what I have

#!/bin/bash

test() {
   INPUT=$(cat)
   echo "IT WORKED $INPUT $1 $2"
}

echo "TEST2" > test.log | cat | test "Hi " "John"

My Output

IT WORKED  Hi  John
3
  • splitting output usually requires something like tee
    – thrig
    Jan 11, 2019 at 4:19
  • I tried working with tee as well, however I wasn't able to get it. Something like echo "TEST2" | tee test.log > test "Hi " "John didn't work
    – llea123
    Jan 11, 2019 at 4:21
  • The whole point of tee is to have its standard output be a pipe.  If you say tee (filename) > test …, that will create a file called test, which is not what you want. P.S. Put everything that you tried into the question. Jan 11, 2019 at 5:47

1 Answer 1

1
test() {
   INPUT=$(cat)
   echo "IT WORKED $INPUT $1 $2"
}
echo TEST2 | tee test.log  | test Hi John

output: IT WORKED TEST2 Hi John

test.log contents: TEST2

1
  • Thank you! That worked! I could've sworn I did that, but I must've did something complete different. ++
    – llea123
    Jan 11, 2019 at 19:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .