Re: [Linuxcommand-discuss] Greetings & a Script
Brought to you by:
bshotts
|
From: Bruce B. <bbu...@ea...> - 2002-08-29 00:36:27
|
----- Original Message -----
From: "William Shotts" <wes...@co...>
To: <lin...@li...>
Sent: Monday, August 26, 2002 6:08 PM
Subject: Re: [Linuxcommand-discuss] Greetings & a Script
> On Sunday 25 August 2002 01:26 pm, Bruce Burhans wrote:
>
> > #!/bin/bash
> > # 2.05
> > old=$1
> > new=$2
> > for i in $( ls ); do
> > if [[ $i != *$old ]]; then
> > shift
> > else
> > k=$( basename $i ${old} )
> >
> > mv $i ${k}${new}
> > fi
> > done
>
> 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....
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 have the makings of a really good book there...
(e or otherwise )
Thanks,
Bruce<+>
> --
> ||||| William Shotts, Jr. (bshotts AT panix DOT com)
> ||||| Be a Linux Commander! Follow me to http://linuxcommand.org
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by: OSDN - Tired of that same old
> cell phone? Get a new here for FREE!
> https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
> _______________________________________________
> Linuxcommand-discuss mailing list
> Lin...@li...
> https://lists.sourceforge.net/lists/listinfo/linuxcommand-discuss
|