Ubuntu: Pass value of variabe to the another command



Question:

I have following command:

usb_soundcard_sink=$(pactl list short sinks | grep "alsa_output" | awk '{ print $2 }' | tail -n1)  

It find the sinks name:

sink_index=$(pactl list short sinks | awk -v index_number=$usb_soundcard_sink '$2==index_number {print $1}')  

It find the index number of given sinks i.e $usb_soundcard_sink

Now in the following command I want to pass the $sink_index as parameter.

I tried in the following command:

volume=$(pactl list sinks | perl -000ne 'if(/#$sink_index/){/(Volume:.*)/; print "$1\n"}' | sed 's/.*\ \(.*\)%.*/\1/g')  

But it is not accepted $sink_index as parameter.

So how can i pass the value of sink_index variable to that command?


Solution:1

If you stored sink_index as environment variable you could use $ENV{} instead:

export sink_index=$(pactl list short sinks | awk -v index_number=$usb_soundcard_sink '$2==index_number {print $1}')    volume=$(pactl list sinks | perl -000ne 'if(/#$ENV{sink_index}/){/(Volume:.*)/; print "$1\n"}' | sed 's/.*\ \(.*\)%.*/\1/g')  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »