Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-20-2012, 05:48 AM   #16
Registered: Oct 2011
Location: Bolton, UK
Distribution: Arch local, Debian on VPS
Posts: 258

Rep: Reputation: 41

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.

#!/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
if [ "$1" = "down" ]; then # as above but if the parameter is "down"
	VOL=`echo $VOL-1 | bc` # we reduce the volume
	ossmix pcm $VOL 
if [ "$1" = "mute" ]; then # and finally, if the parameter is "mute"
	ossmix pcm 0 # we set the volume to "zero"
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
1 members found this post helpful.
Old 02-20-2012, 10:59 PM   #17
LQ Newbie
Registered: Feb 2012
Posts: 12

Original Poster
Rep: Reputation: Disabled
^^ ok thanks sir

for now its hard for me to do this, but i will try my best ^^... thanks roken
Old 02-20-2012, 11:32 PM   #18
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,241

Rep: Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407Reputation: 1407
Originally Posted by soniaholly1 View Post
that were not explored by the command yet, then
enhance the command by reinventing its name and adding this option
to its current options.

You may combine related commands into one script also.
copyormovefile (-c -m) filename/s
copyormovefile is the name of the utility
(-c -m) are options that will do the following:
-c for copying filename/s
-m for moving filename/s
This is pretty clearly an assignment, why don't you ask your teacher for help.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ubuntu Verve Command Line Utility metallica1973 Linux - General 3 01-13-2011 07:32 PM
command line disk partition utility Skaperen Linux - Software 5 01-11-2011 07:30 AM
command line setup utility sikkalgopal Mandriva 3 09-14-2004 01:41 PM
Where is Command line utility for Cups and command tutorial mossy Linux - Software 8 01-16-2004 01:24 AM
Command line utility costasm Linux - Software 1 10-24-2003 10:28 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:13 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration