Re: renaming multiple files

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

 



Jeff Woods wrote:

> At 12/9/2004 07:09 PM +0000, Glynn Clements wrote:
> >Jeff Woods wrote:
> >>>         for file in prefix-* ; do
> >>>              mv "$file" "${file##prefix-}"
> >>>         done
> 
> >>What happens if one of the files is named "prefix-prefix-1"?
> >
> >It gets renamed to prefix-1, which is what I would expect.
> 
> No.  Because you used two of "##" it removes all instances of "prefix1" 
> from the front of the variable and the resulting filename would be "1".

Not here:

	$ file=prefix-prefix-1
	$ echo "${file##prefix-}"
	prefix-1

AFAICT, the difference between # and ## (shortest/longest match) is
only relevant if the pattern contains wildcards, not for fixed
strings.

> >>What about "prefix-"?
> >>
> >>I suggest:
> >>
> >>for file in prefix-?*
> >>do
> >>mv "$file" "${file#prefix-}"
> >>done
> >
> >Huh?
> 
> I added "?" to the pattern so that a file with the exact name "prefix-" 
> would not be selected since that would result in a modified filename that 
> was an empty string.

OK.

-- 
Glynn Clements <glynn@xxxxxxxxxxxxxxxxxx>
-
: send the line "unsubscribe linux-admin" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Newbie]     [Audio]     [Hams]     [Kernel Newbies]     [Util Linux NG]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Device Drivers]     [Samba]     [Video 4 Linux]     [Git]     [Fedora Users]

  Powered by Linux