From nobody Thu Feb 16 12:03:13 2023 X-Original-To: freebsd-questions@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PHYW34dHnz3q6Pp for ; Thu, 16 Feb 2023 12:03:27 +0000 (UTC) (envelope-from freebsd@qeng-ho.org) Received: from mailout.qeng-ho.org (mailout.qeng-ho.org [217.155.128.244]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4PHYW21gBGz4MQZ for ; Thu, 16 Feb 2023 12:03:25 +0000 (UTC) (envelope-from freebsd@qeng-ho.org) Authentication-Results: mx1.freebsd.org; none Received: from [IPV6:2a02:8010:64c9:1::2] (unknown [IPv6:2a02:8010:64c9:1::2]) by mailout.qeng-ho.org (Postfix) with ESMTP id 2815A24FD6; Thu, 16 Feb 2023 12:03:17 +0000 (GMT) Message-ID: <356c7788-c9b7-490a-a014-3c7631c10743@qeng-ho.org> Date: Thu, 16 Feb 2023 12:03:13 +0000 List-Id: User questions List-Archive: https://lists.freebsd.org/archives/freebsd-questions List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-questions@freebsd.org X-BeenThere: freebsd-questions@freebsd.org MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: remove double quote character from file names Content-Language: en-GB To: Polytropon , Sysadmin Lists Cc: freebsd-questions@FreeBSD.org, Per olof Ljungmark References: <1398045780.627028.1676532009651@ichabod.co-bxl> <20230216112431.8252a3d4.freebsd@edvax.de> From: Arthur Chance In-Reply-To: <20230216112431.8252a3d4.freebsd@edvax.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4PHYW21gBGz4MQZ X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:13037, ipnet:217.155.0.0/16, country:GB] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N On 16/02/2023 10:24, Polytropon wrote: > 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)... ;-) Newlines are allowed in filenames. The only characters that aren't are NUL and '/' (at least for Unix-like file systems). Years ago, when ls showed filenames literally including any newlines, I played a trick on a colleague by creating a directory in his home directory that looked exactly like the ls of the home directory, and moving all other files and directories into it. It took 15 minutes of increasing curses before he said "alright, what have you done and how do I get out of it?". -- We build our computer systems the way we build our cities; over time, without a plan, on top of ruins. — Ellen Ullman