‘Well it’s only passing mv a list of–’ yeah yeah yeah, I know, and that’s why I’m calling bullshit. It should be massively harder to execute filenames. Even if 1970s decisions make that the eternal hideous default: the lack of any idiot-proof standard workaround is incomprehensible.

StackOverflow’s full of competing one-liners and people pointing out how each one is considered harmful. The least-skeezy options use exec. That sentence should make anyone recoil in horror.

This is not a filename problem. This is a tool problem. If a single printable character is going to silently expand into a list of names, then for god’s sake, having it put each name in quotes should be fucking trivial.

  • GenderNeutralBro@lemmy.sdf.org
    link
    fedilink
    arrow-up
    2
    ·
    9 months ago

    Some hideous escape syntax ought to force *.jpg to appear as “-a.jpg” instead of -a.jpg, once it reaches mv

    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:

    ls -laR
    ls "-laR"
    ls '-laR'
    

    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.worksOP
      link
      fedilink
      arrow-up
      1
      arrow-down
      2
      ·
      9 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
        link
        fedilink
        arrow-up
        3
        ·
        edit-2
        9 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"), variable expansion (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
          link
          fedilink
          arrow-up
          2
          ·
          9 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.

          • NeatNit@discuss.tchncs.de
            link
            fedilink
            arrow-up
            1
            ·
            9 months ago

            Okay, I pretty much agree with you in theory, but in practice you’re basically describing PowerShell which I just cannot. :P

            • GenderNeutralBro@lemmy.sdf.org
              link
              fedilink
              arrow-up
              2
              ·
              9 months ago

              LOL. Now I feel dirty.

              To be fair, there’s a lot that PowerShell does much better than Bash and similar shells. Piping tables as tables is rad.

        • mindbleach@sh.itjust.worksOP
          link
          fedilink
          arrow-up
          1
          ·
          9 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.

          • NeatNit@discuss.tchncs.de
            link
            fedilink
            arrow-up
            1
            ·
            9 months ago

            I’ve been using command-line programs for twenty-five years.

            A general statement (not about you):

            I’ve been using my human body for over 25 years (exact number withheld) and still don’t know shit about how it works and what it does. I don’t even know the muscle groups, which most people who care about their health learn. But I still use them. Years of experience don’t always translate to understanding and knowledge.

            More specifically about you (and me): I’m sure you know a lot about how to use the shell, and I’ll absolutely bet you know more tricks than me to get shit done. But you still didn’t know about the quoting thing. I have a tendency to dig into understanding how shit works while not developing my actual skills in using them. You might have the opposite tendency. The best is somewhere in the middle, I think.