Comment on mv *.jpg is complete bullshit.
mindbleach@sh.itjust.works 8 months agoThere’s no way around that without reinventing the entire OS.
Disagree. If wildcard expansion is not a feature of the tool, it shouldn’t be up to the tool to shape how each expanded input is passed. Some hideous escape syntax ought to force *.jpg
to appear as “-a.jpg”
instead of -a.jpg
, once it reaches mv
.
Instead *
is acting as a cheeky little ls
alternative, minus any degree of formatting control, and piping actual ls
input into mv
is similarly fraught with complications.
GenderNeutralBro@lemmy.sdf.org 8 months ago
The issue here is that there’s no difference here between
-a.jpg
and“-a.jpg”
.Go ahead and try these commands. They are 100% equivalent:
The reason these are equivalent is because quoting (and expansion, and globbing) is processed in the shell. The shell then passes the evaluated string as an argument to the tool. All of those evaluate to the same string, so they look exactly the same to the
ls
command.What is the solution if there’s a file name that matches something the tool thinks is an argument? What would the correct behavior be?
The only solution is to include some way to communicate to the tool what each argument is. In practice, you could do
ls – *
and it would work even if the first filename was “-laR”. However, not all tools use the–
convention. This is really core to the design of the OS, in that command arguments have no type.mindbleach@sh.itjust.works 8 months ago
Jesus. That’s beyond Javascript levels of “helpfully” reinterpreting strings. That’s borderline Excel behavior.
What is the point of strings allowing every character besides
\0
if they’re gonna eat quotation marks?NeatNit@discuss.tchncs.de 8 months ago
All I can tell you is that, in my opinion, it’s ridiculous and terrible that old-school terminals haven’t been replaced yet with something more user-friendly and self-explanatory, at least in the same-machine user space. But given that they are what they are, some basic understanding of what shells do is required in order to use them, and you don’t have that understanding (I don’t fault you for this).
The key point here is that programs/commands always receive an array of string arguments, and it’s the shell’s job to translate your command line into that. Quoting (like in
-m=“my message”
), shell variables (like$HOME
) and various other things are processed by the shell and not the program, and the expectation is that the user knows this. So quotes are never visible to programs, and the upside is that programs never need to process such quotes - making these features universal without having various random bugs in each program’s implementation.GenderNeutralBro@lemmy.sdf.org 8 months ago
This is exactly correct. This is why I say it would require a whole new OS with no regard for compatibility with current systems.
As long as arguments are typeless and transmitted in a single array, there is no universal way to make programs distinguish between an option and file name that are identical. Full stop. No way. This has nothing to do with quoting schemes.
There are conventions to work around this (like
–
) but that is at the command level, NOT the shell level. It is not universal.mindbleach@sh.itjust.works 8 months ago
I’ve been using command-line programs for twenty-five years. “Basic” is not the issue, here. This is obscene edge-case behavior for what honestly should be a Hello World level example.
Thoroughly explicable causes do not make the outcome any less of a problem.