Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.unix.programmer Subject: Re: Long filenames in DOS/Windows and Unix/Linux Date: Tue, 03 Sep 2024 17:27:34 -0700 Organization: None to speak of Lines: 50 Message-ID: <87bk141cw9.fsf@nosuchdomain.example.com> References: <9e7a4bd1-bfbb-4df7-af1a-27ca9625e50bn@googlegroups.com> <20240903084440.0000663d@gmail.com> <20240903103327.395@kylheku.com> <20240903113937.000008a3@gmail.com> <20240903130000.933@kylheku.com> <20240903132547.00000656@gmail.com> <87seug1iyj.fsf@nosuchdomain.example.com> <87o7541ggd.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Wed, 04 Sep 2024 02:27:35 +0200 (CEST) Injection-Info: dont-email.me; posting-host="0c8cc2609bc8d9fbbbb3d106ce45f413"; logging-data="3715429"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1nYAlNXrYtjmYHEeUugz2" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:Nb539IpoZKD2E4jYxSJBg1/V/nI= sha1:kINmlKWkJqr3Xdup2PUIDYs20DU= Bytes: 3280 Lawrence D'Oliveiro writes: > On Tue, 03 Sep 2024 16:10:42 -0700, Keith Thompson wrote: >> Lawrence D'Oliveiro writes: >>> On Tue, 03 Sep 2024 15:16:36 -0700, Keith Thompson wrote: >>>> For example, I might type something like: >>>> >>>> for file in * ; do cp -p $file $file.bak ; done >>> >>> It’s quite easy to fix that to work with spaces in file names. >> >> I wouldn't call it "quite easy". > > As easy as this, in Bash at least: > > IFS=$'\n' > > I’ve been told elsewhere that $'\n' is also valid in the latest Posix > spec. Not bad -- but of course that's not all you have to do. I tried it just now. My first attempt was IFS='\n' for file in * ; do cp -p $file $file.bak ; done but that's a syntax error ("for" is a shell keyword, not a command). 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. Either of these seems to work: ( IFS='\n' ; for file in * ; do cp -p $file $file.bak ; done ) { IFS='\n' ; for file in * ; do cp -p $file $file.bak ; done } That's still more trouble than it's worth *for me*. It handles 99+% of real-world cases, but I expect it would fail if a file had a newline in its name. (Actually a quick experiment indicates that that seems to work. I don't know how or why.) I have other ways of handling this kind of thing if I need 100% reliability regardless of any funny characters in file names (Perl, readdir). And the simple "for file in *" handles 99% of the cases that I personally have to deal with. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */