Re: [Linuxcommand-discuss] Greetings & a Script
Brought to you by:
bshotts
|
From: William S. <wes...@co...> - 2002-08-29 02:14:43
|
On Wednesday 28 August 2002 08:36 pm, Bruce Burhans wrote: > > First, you could simplify it by doing the following: > > > > #!/bin/bash > > > > old=$1 > > new=$2 > > > > for i in *$old; do > > k=$(basename $i $old) > > mv $i $k$new > > done > > > > I haven't tested this, but it looks right ;-) > > Bill.....I have bad news and good news..... > > The script above puts the new extension on every file > in the directory, regardless of its present extension... > The test part is needed.... Try it again Bruce. The "for" will only select files that have the old extension. Make sure you are using: for i in *$old; and not for i in * $old; If you include a space between the "*" and the "$old", it will process all the files. > > I am a good way through your scripting tutorial, and it > is the best one out of a half-dozen I have on my box.. > > You take the time to explain what is going on, to answer > obvious questions that pop up, and are oriented towards > functionality. For example: Not one of the other tutorials > mentions that you bash has a help command..... > > I've read the entire bash reference manual, and had no > idea that such a thing existed.......Nor do any of them > tell you that you put a function in your .bashrc.....! > (why don't you need to chmod +rx it ? ) or enter them > on the cli..... You don't need to make it executable because it's not executed, it's sourced. That is, it is read as input by another script, usually .bash_profile. > You have the makings of a really good book there... > (e or otherwise ) Maybe someday. I'd be happy just to have enough time to write the next lesson. -- ||||| William Shotts, Jr. (bshotts AT panix DOT com) ||||| Be a Linux Commander! Follow me to http://linuxcommand.org |