[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Unix-ify File Names



Frank Terbeck wrote:
> Thomas Jollans <thomas@jollans.com>:
> [...]
> 
> zsh, yay! :-)
> Just a few remarks.
> 
>> #!/bin/zsh
>>
>> FS="
>> "
> 
> IFS, I suppose. But: Why do you set it?
ugh... good question. I wrote this ages ago ;-)

> 
>> for f in **/*
> 
>   for i in ./**/* # make f=./$f unneeded below.
> 
>> do
>>   #required for files in the current dir.
>>   f=./$f
>>   #dir of file
>>   fp1=${f%/*}/
> 
>     fp1={$f:h}    # (think (h)ead)
> 
>>   #name of file
>>   fp2=${f##*/}
> 
>     fp2=${f:t}    # (think (t)ail)
> 
>>   #dir should already be anti-spaced and lower-cased
>>   f=$fp1:gs/\ /_/:l$fp2
>>   #the new name; anti-spaced and lower-cased
>>   f2=$f:gs/\ /_/:l
>>
>>   if ! [[ $f = $f2 ]]
>>   then
>>     mv -v "$f" "$f2"
>>   fi
>> done
> 
> Of course, your expansions do work (and they are portable, as they
> work in every POSIX shell), but if you use zsh already, why not ':t'
> and ':h', as they are easier to read, IMHO. :-)
> 
> Recursive globbing is just a wonderful feature, isn't it? :-)
definitely.

Thanks for the comments :-)

Thomas


Attachment: signature.asc
Description: OpenPGP digital signature


Reply to: