Sujet : Re: Long filenames in DOS/Windows and Unix/Linux
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.unix.programmerDate : 04. Sep 2024, 05:36:48
Autres entêtes
Organisation : None to speak of
Message-ID : <8734mg11cv.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
User-Agent : Gnus/5.13 (Gnus v5.13)
Lawrence D'Oliveiro <
ldo@nz.invalid> writes:
On Tue, 03 Sep 2024 17:27:34 -0700, Keith Thompson wrote:
Second attempt:
IFS='\n' ; for file in * ; do cp -p $file $file.bak ; done
but that leaves IFS set to its new value in my interactive shell.
>
Which in my experience is no biggie.
Perhaps. Honestly, I've never paid enough attention to IFS to have any
confidence in doing anything other than leaving it alone.
Next step: what if you wanted to handle newlines in file names as well?
Either `find ... -print0 | xargs -0 ...` or a quick Perl script.
opendir my $DIR, '.' or die ".: $!\n";
foreach my $file(grep { $_ ne '.' and $_ ne '..' } readdir $DIR) {
system 'cp', '-p', $file, "$file.bak";
# error checking omitted for now
}
closedir $DIR;
(I'm not arguing that Perl is the best or only language for this; it
just happens to be what I'm most familiar with.)
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */