delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2020/03/03/18:26:37

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:message-id:date:from:mime-version:to:subject
:references:in-reply-to:content-type:content-transfer-encoding;
q=dns; s=default; b=dZAJV/IHsbikNaKvzufo/KbJ1jslISwW3RhjDT70dfK
USHaeNslRKu23YbATYyHQZ1GMc8Eah38iFMiqWsBsWZRa2mzPLzlD7Qh9EFqo3vW
xeg38uAyqv0oNALbr+2Sgi1N5u7pr1/G8VyVV1FF0RTwxcOZMq61gU2rlZZlo7AE
=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:message-id:date:from:mime-version:to:subject
:references:in-reply-to:content-type:content-transfer-encoding;
s=default; bh=i4BswyE79jbNlBgJNbtM1TVaD8M=; b=Iq6zxhojQxYp/yUpg
wcEb4SUPudCkLxPIXwtVQalnbwpuxWdWEUbHPR4lWT2w5q16gZDAqZ8nb9sWdxJ4
NNzLPIIk/rsO2KCC295ja29yzfi0hz8MoDGz2bXZXdXuzLmBxGFbGqfxyS/E4wKz
WTGYM/DzFeXNh2GekN5Wu43eE4=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Spam-SWARE-Status: No, score=-5.6 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,SPF_PASS autolearn=ham version=3.3.1 spammy=meta
X-HELO: Ishtar.sc.tlinx.org
Message-ID: <5E5EE76B.8000202@tlinx.org>
Date: Tue, 03 Mar 2020 15:25:31 -0800
From: L A Walsh <cygwin AT tlinx DOT org>
User-Agent: Thunderbird
MIME-Version: 1.0
To: Fergus Daly <fergusd84 AT outlook DOT com>,
"cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com>
Subject: Re: Has rename syntax changed?
References: <AM6PR03MB5282DB8DBC61B8331D880434A4E80 AT AM6PR03MB5282 DOT eurprd03 DOT prod DOT outlook DOT com>
In-Reply-To: <AM6PR03MB5282DB8DBC61B8331D880434A4E80@AM6PR03MB5282.eurprd03.prod.outlook.com>
X-IsSubscribed: yes

On 2020/02/28 04:38, Fergus Daly wrote:
> I am almost certain that the command
> $ rename "anything" "AnyThing" *.ext
> would alter the string from lc to uc as shown, anywhere it occurred in any filename in *.ext in the current directory.
>   
isn't that they same as "mv anything.xxx Anything.xxx" ?


> What I remember as past behaviour now fails, leaving he filename unaltered.
>   

/tmp> ll *.xxx
-rw-rw-rw-+ 1 0 Mar  3 14:30 anything.xxx
/tmp> rename any Any *.xxx
/tmp> ll *.xxx
-rw-rw-rw-+ 1 0 Mar  3 14:30 Anything.xxx
---
    Works here on a local NTFS file system.
> (Failure in much the same way as mv would fail if the similar attempt was made.)
>   
----
???
Like this?:

/tmp> touch anything.xxx
/tmp> mv anything.xxx Anything.xxx
/tmp> ll *.xxx
-rw-rw-rw-+ 1 0 Mar  3 14:30 Anything.xxx
/tmp> rename Any any *.xxx
> (Good old DOS command rename (or the abbreviation ren) used to achieve multiple-rename in an easy manner that just eludes bash.)
>   
---
    'rename' is not a bash builtin or feature, neither is 'mv' nor
my preference: 'mmv':

/tmp> ll *.xxx
-rw-rw-rw-+ 1 0 Mar  3 14:30 anything.xxx
/tmp> mmv 'a*.xxx' 'A#1.xxx'      #(same as "mmv a\*.xxx A\#1.xxx' )
/tmp> ll *.xxx
-rw-rw-rw-+ 1 0 Mar  3 14:30 Anything.xxx

FWIW: w/mmv, meta chars like '*' in source and '#' in target need to be
quoted to protect from shell expansion.

> Anyway: has something altered (and quite recently, i think), or am I just mis-remembering the versatility of the command rename?
>   
----
    I think that the 'whatever' that has changed is likely a different
file system.

    Besides the above tests/examples on Win7/NTFS, I got similar results
on a network share from a Linux-Samba server.

Oh -- one more potential gotcha:

the '*.xxx' pattern you are giving to rename is subject to shell
expansion (shell being bash in this case).  If the *.xxx doesn't
match all your targets and bash doesn't have 'nocaseglob' set, you
can get:

/tmp> shopt -u nocaseglob nocasematch
/tmp> rename Anything anything *.xxx
rename: *.xxx: not accessible: No such file or directory
/tmp> shopt -s nocaseglob nocasematch
/tmp> rename Anything anything *.xxx

Why?: because my filename was 'Anything.Xxx' (Anything.XXX would do the 
same).

Even though the file system ignores case, if bash is told
not to ignore case, the '*.xxx' won't match anything but all lower
case extensions.

It's a contrived case, but illustrates that the pattern at
the end isn't seen by 'rename' because it is 1st expanded by bash.

Hope this helps, and isn't overkill! ;-)





--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019