Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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')
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.