Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Feb 2023 22:42:05 +0100 (CET)
From:      Sysadmin Lists <sysadmin.lists@mailfence.com>
To:        freebsd-questions@FreeBSD.org
Cc:        Per olof Ljungmark <peo@nethead.se>, Polytropon <freebsd@edvax.de>
Subject:   Re: remove double quote character from file names
Message-ID:  <380646460.28908.1676583725362@fidget.co-bxl>
In-Reply-To: <20230216112431.8252a3d4.freebsd@edvax.de>
References:  <d83c93ad-0eac-d41a-c7db-79a1e1bc62d8@nethead.se> <1398045780.627028.1676532009651@ichabod.co-bxl> <20230216112431.8252a3d4.freebsd@edvax.de>

next in thread | previous in thread | raw e-mail | index | archive | help
> ----------------------------------------
> From: Polytropon <freebsd@edvax.de>
> Date: Feb 16, 2023, 2:24:31 AM
> To: Sysadmin Lists <sysadmin.lists@mailfence.com>
> Cc: <freebsd-questions@FreeBSD.org>, Per olof Ljungmark <peo@nethead.se>
> Subject: Re: remove double quote character from file names
> 
> 
> On Thu, 16 Feb 2023 08:20:09 +0100 (CET), Sysadmin Lists wrote:
> > [...]
> > Just to throw in an awk-themed solution:
> > $ ls -1 | awk '/"/ { system("mv -v '\''" $0 "'\'' " $0) }'
> > 
> > $ touch "\"foo bar\"" \"baz\" \".zap\" xyz abc
> > $ ls -1A
> > ".zap"
> > "baz"
> > "foo bar"
> > abc
> > xyz
> > $ ls -1 | awk '/"/ { system("mv -v '\''" $0 "'\'' " $0) }'
> > ".zap" -> .zap
> > "baz" -> baz
> > "foo bar" -> foo bar
> > $ ls -1A
> > .zap
> > abc
> > baz
> > foo bar
> > xyz
> > 
> > There's a clever use of the existing double-quotes in the filenames
> > in the renaming.
> 
> This is actually a quite clever "ab"use of existing quotes.
> 
> Just a friendly sidenote:
> 
> Never expect anything. It _might_ be possible that filenames
> such as
> 
> 	foo "bar" blah.txt
> 	"meow" 123.dat
> 	doodle "boo" .c++
> 	-my brain hurts ."tar".gz
> 
> exist in the heap of files to be processed. Selecting a good
> delimiter for input files is hard. Using the "IFS = \n" approach
> works - as long as there are no newlines in filenames (which
> I'm not sure could also be allowed)... ;-)
> 
> 
> 
> -- 
> Polytropon
> Magdeburg, Germany
> Happy FreeBSD user since 4.0
> Andra moi ennepe, Mousa, ...
> 

Those are good points. But in this case we know what happened:
The OP accidently named a bunch of files with double-quotes when he meant to
simply enclose them in double-quotes. Which means those possible edge cases
aren't present. Still good points worth considering for other scenarios.


-- 
Sent with https://mailfence.com  
Secure and private email



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?380646460.28908.1676583725362>