PDA

View Full Version : amixer get 'Master' | grep [on]?



jmc1024
July 22nd, 2007, 12:12 AM
I'm trying to write a script to toggle sound on and off. How do I escape the braces in the grep command so that they are part of the search pattern?

amixer get 'Master' | grep [on]
if [ 0 -e $? ];
then
amixer set 'Master',0 mute
else
amixer set 'Master',0 unmute
fi

I guess I could send amixer's output to /tmp/trash and then grep that, but I hate generating trash if I don't have to.

Thanks,
Mark

scxtt
July 22nd, 2007, 12:22 AM
this seems to work:

:> cat test.txt
this is a [test].
this is a {test}.

:> cat test.txt | grep "\[test\]"
this is a [test].

aanderse
July 22nd, 2007, 01:30 AM
hey

to [toggle] mute amixer you could do something like this

amixer -q set Master toggle
amixer -q set PCM toggle
etc ...

-q stands for quiet so no text output is spewed

jmc1024
July 22nd, 2007, 01:31 AM
Okay double quotes _and_ escape characters.
Thanks, Mark

jmc1024
July 22nd, 2007, 01:34 AM
Hmmm.... Didn't see than in the amixer man page but it does in fact work. Oh well, I learned two things today.
Thanks, Mark