From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 42242158042 for ; Wed, 30 Oct 2024 03:05:42 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id F3365E0815; Wed, 30 Oct 2024 03:05:33 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id E5B17E07C5 for ; Wed, 30 Oct 2024 03:05:32 +0000 (UTC) Message-ID: <76de2cf9-c045-45c3-b4ed-9c549beadfa1@gentoo.org> Date: Tue, 29 Oct 2024 23:05:29 -0400 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@lists.gentoo.org Reply-to: gentoo-user@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [gentoo-user] Renaming files with those pesky picture type characters. To: gentoo-user@lists.gentoo.org References: <32f571c7-de3f-53da-185a-9cdfa0797a93@gmail.com> <4973073.31r3eYUQgx@rogueboard> <2d8f86e2-923a-cc81-e56d-63135b379737@gmail.com> <2973073.e9J7NaK4W3@rogueboard> <0c892dd0-a1d1-4372-ad62-a64cd751e270@gmail.com> Content-Language: en-US From: Eli Schwartz Autocrypt: addr=eschwartz@gentoo.org; keydata= xjMEZmeRNBYJKwYBBAHaRw8BAQdAYNZ7pUDWhx1i2f3p6L2ZLu4FcY18UoeGC04Gq/khqwfN I0VsaSBTY2h3YXJ0eiA8ZXNjaHdhcnR6QGdlbnRvby5vcmc+wpYEExYKAD4WIQTvUdMIsc4j CIi+DYTqQj6ToWND8QUCZoRL+gIbAwUJBKKGAAULCQgHAwUVCgkICwUWAgMBAAIeBQIXgAAK CRDqQj6ToWND8aB5AP9r4kB691nNtNwKkdRiOdl7/k6WYzokvHvDamXxRJ0I+gEAjZqR5V8y mfR3fy2Z+r2Joeqdt3CIv5IwPs64spBvigLOOARmZ5E0EgorBgEEAZdVAQUBAQdATT46Z06b 1X9xjXFCYFxmq/Tj3tSEKZInDWTpoHQp4l8DAQgHwn4EGBYKACYWIQTvUdMIsc4jCIi+DYTq Qj6ToWND8QUCZmeRNAIbDAUJBKKGAAAKCRDqQj6ToWND8a2RAP40KPfbfoiZAJW5boFmFJ3G TUBDJRh9CWHyaPqq2PN+0wD/R07oLzfnJUN209mzi9TuTuHjeZybysyqXSw4MAxkMAY= In-Reply-To: <0c892dd0-a1d1-4372-ad62-a64cd751e270@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------0ea6XcmHv7H8t5kbriep4z0x" X-Archives-Salt: 937276fd-79c4-49a1-8f32-f9001173f8a9 X-Archives-Hash: 0c76848e98096558b239963274d4eca2 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --------------0ea6XcmHv7H8t5kbriep4z0x Content-Type: multipart/mixed; boundary="------------J2Bu3FYpAsMLMP9O6lffdy4A"; protected-headers="v1" From: Eli Schwartz To: gentoo-user@lists.gentoo.org Message-ID: <76de2cf9-c045-45c3-b4ed-9c549beadfa1@gentoo.org> Subject: Re: [gentoo-user] Renaming files with those pesky picture type characters. References: <32f571c7-de3f-53da-185a-9cdfa0797a93@gmail.com> <4973073.31r3eYUQgx@rogueboard> <2d8f86e2-923a-cc81-e56d-63135b379737@gmail.com> <2973073.e9J7NaK4W3@rogueboard> <0c892dd0-a1d1-4372-ad62-a64cd751e270@gmail.com> In-Reply-To: <0c892dd0-a1d1-4372-ad62-a64cd751e270@gmail.com> --------------J2Bu3FYpAsMLMP9O6lffdy4A Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 10/29/24 2:05 PM, Dale wrote: > I saw that but never understood what it did. I thought it was > something that worked just with revdep-rebuild or something. So it > is a bash thing. Interesting. That could open a can of worms. It's not a bash thing. It is a software thing. It is mandated by the POSIX standard: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html That means, as a general rule of thumb, all Unix commands required to exist everywhere, *have to* support the usage of "--" in this manner. And since it is a sensible thing to do, most programs, even not POSIX programs, heed the wise advice of POSIX and support "--". On 10/29/24 11:18 AM, Dale wrote: > Howdy, >=20 > I downloaded some files. I have a few that have some weird names. > Some have those picture type characters. Some start with a dash, > "-". In some cases I can use wild cards to change them. Frank gave > me some ideas on that off list, while discussing his nifty checksum > tool. Anyway, I ran up on a few that start with a dash, "-", and I > can't find a way around that. The mv command thinks it is me trying > to include a option. It spits out something like this. >=20 >=20 > mv: unrecognized option '---ne.avi' >=20 >=20 > Some of the other characters I run into look like this. >=20 >=20 > =EF=BF=BD=EF=BF=BD=EF=BF=BD=EF=BF=BD >=20 >=20 > Those I can usually get around with wildcards. I have not found a > way to get around the ones with the dash in front tho. I tried a > single quote, double quote etc but still no worky. Also, tab > completion doesn't help either. I feel like, in combination with the bash comment above, this speaks to a general misunderstanding of how quotes, dashes, wildcards, etc work. So I would like to clarify something here. If you try to $ mv ---ne.avi new-filename.avi and it doesn't work, and you try $ mv "---ne.avi" new-filename.avi Or more generally, if you have a filename named this is a weird filename.avi You have various options for writing a "mv" command for it in a bash shell, but that's not actually what the "mv" program sees. Example: $ mv "this is a weird filename.avi" better.avi is actually executed as an operating system array: {"mv", "this is a weird filename.avi", "better.avi"} You can also do: $ mv this\ is\ a\ weird\ filename.avi better.avi Still, bash tries to figure out how to convert it into an operating system array, and gets: {"mv", "this is a weird filename.avi", "better.avi"} You can even do: $ mv *weird*filename.avi" better.avi Still, bash tries to figure out how to convert it into an operating system array, and gets: {"mv", "this is a weird filename.avi", "better.avi"} It's always converted to that array. But, $ mv this is a weird filename.avi better.avi becomes this array: {"mv", "this", "is", "a", "weird", "filename.avi", "better.avi"} and obviously that is an entirely different command because the array is different (each part is a different filename, as far as "mv" knows.) Same with stuff that begins with a dash. $ mv "---ne.avi" new-filename.avi $ mv '---ne.avi' new-filename.avi $ mv ---ne.avi new-filename.avi $ mv *-ne.avi new-filename.avi $ mv \-\-\-ne.avi new-filename.avi all become {"mv", "---ne.avi", "new-filename.avi"} Which does not help you because the array values that the "mv" command sees are still starting with a single dash. =46rom bash (and from bash tab completion) all you can do is update bash text lines which then get translated into arrays so you can execute the array as a program. Quoting and wildcards do NOT affect how "mv" works. All that quoting and wildcards do is affect whether space characters are interpreted as part of the filename or as the separator between different array items. The "mv" program is responsible for knowing what a dash is or does. It tries first to treat it as an option, and that's why "--" works -- because it tells "mv" itself to stop treating it as an option, and to treat it as a filename instead. That is also why "./---new.avi" works. All filenames (except those starting with / such as /home or /usr, of course) can have an added directory at the beginning, and the obvious one is ./ but you could also use "$PWD/---new.avi" if you wanted. Since it doesn't start with a dash, it can't be an option. --=20 Eli Schwartz --------------J2Bu3FYpAsMLMP9O6lffdy4A-- --------------0ea6XcmHv7H8t5kbriep4z0x Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature.asc" -----BEGIN PGP SIGNATURE----- wnsEABYIACMWIQTnFNnmK0TPZHnXm3qEp9ErcA0vVwUCZyGieQUDAAAAAAAKCRCEp9ErcA0vV0ce AQCN1PvuOyTAdtRALrIkK6zKRYugl9mqPCL5aGjSWFXSKQD+NpkpVHdxrjdPMiwoWtjH6D1e8D5T g1hJ4OUh3PAWoAY= =v2Wv -----END PGP SIGNATURE----- --------------0ea6XcmHv7H8t5kbriep4z0x--