Am 09. Nov, 2005 schwätzte Bill Jonas so:
> On Tue, Nov 08, 2005 at 06:25:41PM -0700, Josef Lowder wrote:
>> I've been making a shell script like this to rename them,
>> but even doing this in a text editor, editing one line at a time,
>> gets tedious:
>>
>> mv pict0001.jpg a001.jpg
>> mv pict0002.jpg a002.jpg
>> mv pict0003.jpg a003.jpg
>
> for file in pict*.jpg; do mv $file ${file//pict/a/}; done
Hmm, haven't used the substitution before. You got me to check out the man
page :).
It looks like he actually wants to leave off the last slash as it becomes
part of the replacement. He also should leave off one of the first two
slashes as he only wants to replace pict once.
I'd also suggest using -i for mv in this case to make sure he doesn't
accidentally whack something.
for file in pict*.jpg; do mv -i $file ${file/pict/a}; done
Thanks for demonstrating ${parameter/pattern/string} for us! I'm gonna
have to start using that...
lufthans@LuftHans:~$ ( a=fredfred; echo ${a//re/er/} )
fer/dfer/d
lufthans@LuftHans:~$ ( a=fredfred; echo ${a//re/er} )
ferdferd
lufthans@LuftHans:~$ ( a=fredfred; echo ${a/re/er} )
ferdfred
ciao,
der.hans
--
#
https://www.LuftHans.com/
# Nobody grows old merely by living a number of years.
# We grow old by deserting our ideals.
# Years may wrinkle the skin, but to give up enthusiasm
# wrinkles the soul. -- Samuel Ullman---------------------------------------------------
PLUG-discuss mailing list -
PLUG-discuss@lists.plug.phoenix.az.us
To subscribe, unsubscribe, or to change you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss