Results 1 to 4 of 4
I'm not sure how to explain what I want to do exactly, so I'll use a couple of examples of things I want to do:
Let's say using LAME with ...
- 04-29-2008 #1Just Joined!
- Join Date
- Apr 2008
- Location
- Melbourne, Victoria, Australia.
- Posts
- 11
I need some BASH help, please.
I'm not sure how to explain what I want to do exactly, so I'll use a couple of examples of things I want to do:
Let's say using LAME with one of the presets.
lame --preset insane "Some directory/some song.mp3" "Some other directory/new song.mp3"
The red text being the variables, so I could make the BASH script, name it whatever like "insane" for example, and place it in my binaries directory so then I would launch:
insane "Some directory/some song.mp3" "Some other directory/new song.mp3"
Or another example, using APT:
sudo apt-get install some-program -y --force-yes -qq
and then I could call that script like "installz" for example, put in bin, then launch:
installz some-program
I hope I explained what I want to do with those examples.
Essentially it's launching commands with space for variables.
Thanks in advance.
- 04-29-2008 #2
It would be simpler to do this using an alias. You can put one in your .bashrc file. For example
would cause any subsequent call to ls somefile to be interpreted as ls --color somefile so all your directory listings would be automatically colour-coded.Code:alias ls="ls --color"
Last edited by hazel; 04-29-2008 at 04:22 PM. Reason: error correction
"I'm just a little old lady; don't try to dazzle me with jargon!"
- 04-29-2008 #3Just Joined!
- Join Date
- Apr 2008
- Location
- Melbourne, Victoria, Australia.
- Posts
- 11
No. You misinterpreted what I meant. The color is irrelevant. I was using color to show a variable.
I don't know how to explain it in more detail. I simply want to run command via a BASH script, but I do not know what to put for variables.
Like I want to do a command plus various switches, etc but I want the variables such as directories and files to be left out of it and to be inputted manually. So the BASH script will run all the necessary commands and switches, but I have to specify the files. I have no idea if this makes sense. I'm a little drunk, but hopefully it made sense.
EDIT:
Were you using an example when you were talking about ls --color?
If so, how would it work if the switches were after the variable I want to insert? For example look at my apt-get example.
- 04-29-2008 #4
Aliases are great if you want a command to be interpreted as something else. The "ls --color" is a great one. However, this only applies if arguments only come after the interpreted command. In this case, we have variables that are inserted inside of the command, so this is an excellent place for a Bash script with variables.
In Bash, a variable does not need to be declared before it is used, and you get its value by prepending it with '$'. So the variable 'foo' can be accessed as "$foo". Arguments to your script are stored in special variables $1, $2, etc., where $1 is the first arg, $2 is the second, etc.
This is an excellent reference on Bash scripting, certainly the best that I know of:
http://www.tldp.org/LDP/abs/html/
In particular, have a look at this section:
http://www.tldp.org/LDP/abs/html/variables.html
Hopefully this will help you out. If you have any further questions about this, please ask!DISTRO=Arch
Registered Linux User #388732


Reply With Quote