From: Eli Schwartz <eschwartz@gentoo.org>
To: gentoo-user@lists.gentoo.org
Subject: Re: [gentoo-user] Renaming files with those pesky picture type characters.
Date: Tue, 29 Oct 2024 23:05:29 -0400 [thread overview]
Message-ID: <76de2cf9-c045-45c3-b4ed-9c549beadfa1@gentoo.org> (raw)
In-Reply-To: <0c892dd0-a1d1-4372-ad62-a64cd751e270@gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 4444 bytes --]
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,
>
> 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.
>
>
> mv: unrecognized option '---ne.avi'
>
>
> Some of the other characters I run into look like this.
>
>
> ����
>
>
> 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.
From 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.
--
Eli Schwartz
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
next prev parent reply other threads:[~2024-10-30 3:05 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-29 15:18 [gentoo-user] Renaming files with those pesky picture type characters Dale
2024-10-29 15:47 ` Michael
2024-10-29 16:18 ` Dale
2024-10-29 16:40 ` Michael
2024-10-29 18:05 ` Dale
2024-10-30 3:05 ` Eli Schwartz [this message]
2024-10-30 17:25 ` Dale
2024-11-01 2:25 ` Andrew Lowe
2024-11-01 14:16 ` Jack Ostroff
2024-11-01 16:02 ` Dale
2024-11-03 23:52 ` Wol
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=76de2cf9-c045-45c3-b4ed-9c549beadfa1@gentoo.org \
--to=eschwartz@gentoo.org \
--cc=gentoo-user@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox