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

Re: Unix-ify File Names



Thomas Jollans <thomas@jollans.com>:
[...]

zsh, yay! :-)
Just a few remarks.

> #!/bin/zsh
> 
> FS="
> "

IFS, I suppose. But: Why do you set it?

> 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? :-)

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925



Reply to: