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.

Following is the command that find the total sinks of pulseAudio:

pactl list short sinks

Output:

0   alsa_output.pci-0000_00_1b.0.hdmi-stereo    module-alsa-card.c  s16le 2ch 44100Hz   RUNNING
1   alsa_output.usb-0d8c_C-Media_USB_Audio_Device-00-Device.analog-stereo   module-alsa-card.c  s16le 2ch 44100Hz   RUNNING
3   bluez_sink.94_CE_2C_FA_8B_B1    module-bluetooth-device.c   s16le 1ch 8000Hz    IDLE

So I use the following command to find the specific sinks:

pactl list short sinks | grep "C-Media_USB_Audio_Device"

output:

1   alsa_output.usb-0d8c_C-Media_USB_Audio_Device-00-Device.analog-stereo   module-alsa-card.c  s16le 2ch 44100Hz   RUNNING

This print the specific sink name with index. I want store this index 1 in the variable so I can use it in my another logic.

share|improve this question
    
You really need to use a more descriptive title. You didn't mention anything about ALSA or sound. Besides that, what are you trying to do here? Why are you trying to manipulate ALSA directly instead of using PulseAudio? pactl and pacmd are very capable, and it's usually better to work through them than directly manipulate ALSA. –  blujay Apr 28 at 5:23
    
@blujay - I have edited my question. –  Prakash V Holkar Apr 28 at 5:57
    
I still don't understand what you are trying to do. I've rewritten my ~/.pulse/config/default.pa file to turn my surround output into two separate stereo outputs, and I've written a script to automatically mute PA devices when my system suspends/resumes, so I have a little knowledge here. What are you trying to do? –  blujay Apr 28 at 6:00
    
Please specify the exact input and output you expect. –  i08in Apr 28 at 6:03
    
@Jobin - I specify what exact I want, can you please look it once –  Prakash V Holkar Apr 28 at 6:20

1 Answer 1

up vote 1 down vote accepted

I think this is what you looking for,

$ var=$(pactl list short sinks | awk '$2=="alsa_output.usb-0d8c_C-Media_USB_Audio_Device-00-Device.analog-stereo" {print $1}')
$ echo $var
1
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.