I came across this useful little script when playing about with RadioPi – since I couldn’t here the text-to-speech output very easily when I was testing, and had no idea how to change the volume from the command line. You can simply add the following lines at the end of ~/.bashrc (to open in a text editor: sudo nano ~/.bashrc). You’ll need to log out and log back in again, and then simply enter volu or vold at the command line to change the volume by 5%.

# Increase volume by 5%
alias volu=’sudo amixer set PCM — $[$(amixer get PCM|grep -o [0-9]*%|sed ‘s/%//’)+5]%’
# Decrease volume by 5%
alias vold=’sudo amixer set PCM — $[$(amixer get PCM|grep -o [0-9]*%|sed ‘s/%//’)-5]