Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

piping output into middle of bash command

Somewhat related to this question: Convert audio files to mp3 using ffmpeg

I want to execute a command in one line using piping in BASH.

What I am trying to do is this:

echo "Hello" | somecommand | ffmpeg -i _____ -f mp2 output.mp3 

Where the _____ is the output of somecommand. Is there any way to achieve this?

like image 370
bawse Avatar asked Oct 17 '25 08:10

bawse


2 Answers

Try using xargs

echo "Hello" | somecommand | xargs ffmpeg -f mp2 output.mp3 -i

or

echo "Hello" | somecommand | xargs -i ffmpeg -i {} -f mp2 output.mp3
like image 189
Manuel Barbe Avatar answered Oct 19 '25 22:10

Manuel Barbe


You can use command substitution here in the middle argument:

ffmpeg -i "$(echo 'Hello' | somecommand)" -f mp2 output.mp3 
like image 28
anubhava Avatar answered Oct 19 '25 22:10

anubhava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!