OK - here's a watered down version of my script and what it does. From here, you really should start reading. The forum simply isn't an environment in which you can learn bash scripting, and you have to do the work.
Code:
#!/bin/bash # This tells the script which environment to run the script in - in this case bash
# simple script to mute by changing volume - This is a comment and can include anything you want. It isn't interpreted by the script.
VOL=`ossmix -D pcm | sed 's/.*to \(.*\)\:.*/\1/'` # Again, we are assigning and initialising a variable VOL. This time the output of the following the commands is stored in the variable. Both ossmix and sed are bash commands (that you could run in the terminal). ossmix is the mixer control for the oss soundsystem, and sed is a stream editor used to manipulate whatever string or file is passed to it. By piping the output from ossmix through sed I can extract just the information I want (i.e. the current volume level)
if [ "$1" = "up" ]; then # $1 is the first parameter passed to the script. If it's equal to "up" (i.e. if the script was called with `volumecontrol up` then we
VOL=`echo $VOL+1 | bc` # add 1 to the current volume using the command line calculator `bc`
ossmix pcm $VOL # and increase the volume in oss accordingly
fi
if [ "$1" = "down" ]; then # as above but if the parameter is "down"
VOL=`echo $VOL-1 | bc` # we reduce the volume
ossmix pcm $VOL
fi
if [ "$1" = "mute" ]; then # and finally, if the parameter is "mute"
ossmix pcm 0 # we set the volume to "zero"
fi
This is a simple script with no error checking and no complicated functions. All of what the script does is achieved by using other programs (ossmix, bc, sed, echo). You could a achieve exactly the same thing by typing a series of commands into the terminal, but by writing a script we can automate the process. This is the power of bash. You can automate almost anything provided you have the tools to do what you want to do, but you do need to understand how to write a script, what the syntax of various functions within the bash script are, and you need to know how to use the programs that you intend to invoke with your script. This is why it's important to read and learn. The subject is far to big to deal with in a simple reply on a forum. You have been provided with links to the resources that you need to learn. Now it's time to go and start learning
