Re: Bash Help: Renaming all files in a Directory

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

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mikkel L. Ellertson wrote:
> Todd Zullinger wrote:
>>>> Off the top of my head...  $ for f in *.jpg; do; mv $f `echo $f |
>>>> sed 's/ //g'`; done
>> 
>> The spaces in the file names will make this fail.  The loop will
>> split the files at the spaces, so you'd end up with f=Family, then
>> f=Pic, etc.  You can muck around with the IFS variable, but to me
>> it always seems easier to just use a while loop instead. :)
>> 
> No, the loop will have f=Family Pic 001.jpg but the mv command will
> fail unless you use "$f" because mv will see it as 3 file names,
> split at the spaces.

D'oh!  I should be more careful before correcting anyone.  My
apologies to Patrick and for spreading misinformation. :)

Using a simple patter in the for loop works, it's things where you get
the loop item from a command that it doesn't work.  If you had a file
with some names and tried to do

    for i in $(cat filename); do ...

then you run into the problem I was thinking of.  Even using

    for i $(ls *.jpg); do ...

is a problem (though it's pointless to do it that way).

Anyway, thanks for the correction Mikkel.

- -- 
Todd        OpenPGP -> KeyID: 0xD654075A | URL: www.pobox.com/~tmz/pgp
======================================================================
With reasonable men I will reason; with humane men I will plead; but
to tyrants I will give no quarter.
    -- William Lloyd Garrison

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.4 (GNU/Linux)
Comment: When crypto is outlawed bayl bhgynjf jvyy unir cevinpl.

iG0EARECAC0FAkTBgr4mGGh0dHA6Ly93d3cucG9ib3guY29tL350bXovcGdwL3Rt
ei5hc2MACgkQuv+09NZUB1rngwCgu7Fua+dvV8mTpPAI9LPsDK59I5AAoJOkLdXr
nhA+Cajc/oObBU9NKMlm
=RsRB
-----END PGP SIGNATURE-----


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux