Bash Pipe – Can I Use Pipe Output as a Shell Script Argument?

argumentsbashlinuxpipeshell

Suppose I have a bash shell script called Myscript.sh that need one argument as input.

But I want the content of the text file called text.txt to be that argument.

I have tried this but it does not work:

cat text.txt | ./Myscript.sh

Is there a way to do this?

Best Answer

Command substitution.

./Myscript.sh "$(cat text.txt)"
Related Question