GenderNeutralBro
@GenderNeutralBro@lemmy.sdf.org
- Comment on mv *.jpg is complete bullshit. 8 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.
- Comment on mv *.jpg is complete bullshit. 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. - Comment on mv *.jpg is complete bullshit. 8 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. - Comment on mv *.jpg is complete bullshit. 8 months ago:
Ahhh. That’s a confusing thread, with a couple confounding factors.
The OP in that thread is attempting to a batch rename, which is out of scope of the
mv
command.If you are NOT trying to change the name of the file, I recommend always making the last argument of
mv
your destination directory, rather than the destination file. This is strictly mandatory if you are moving multiple files.OP in that SO thread used the filename as the destination path — a filename which did not exist, and therefore could not be resolved by the wildcard. And if it had existed, the move would have failed. Because of that,
mv /data/*/Sample_*/logs/*_Data_time.err /data/*/Sample_*/logs/*_Data_time_orig.err
is not a valid command.OP cannot accomplish what they want with a single
mv
command. They would need to use a loop or something likefind
.I agree that the lack of universal consistency in how commands handle arguments is unfortunate. There’s no way around that without reinventing the entire OS. Many commands let you pass ‘–’ as an argument to signify that any subsequent arguments should not be interpreted as options even if they begin with ‘-’. But that’s entirely up to the implementation of each program; it’s not a shell feature.
Future OS designers: consider typed arguments. Abandon all legacy cruft.
- Comment on mv *.jpg is complete bullshit. 8 months ago:
This is not standard behavior. Got links to StackOverflow?
This works just fine in bash and zsh:
encoded_funky_name=IUAjJCVeJiooKVtde30nIjo7IGxzOyAmYW1wOyA8Plx8YH5gJChscykke1BBVEh9ISF8fCYmLmpwZw== # decodes to: !@#$%^&*()[]{}'":; ls; & <>\|`~`$(ls)${PATH}!!||&&.jpg mkdir temp cd temp mkdir temp2 touch $(echo "${encoded_funky_name}" | base64 -d) mv ./*.jpg temp2 ls -lR mv temp2/*.jpg . ls -lR
Note that it is recommended to use “./” before a raw * in globs to avoid filenames beginning with “-” being interpreted by the command as special arguments (this is not necessary in the above example, but it is a good habit). See dwheeler.com/essays/filenames-in-shell.html#globb… for more info. e.g.:
touch ./-laR # Bad ls command: ls * # Good ls command: ls ./*
having it put each name in quotes should be fucking trivial
This is effectively what happens, except that it’s actually more robust than that, since it also accounts for names with quotes and other special characters. Glob expansion does NOT output file names into the shell; it passes them as arguments to the command with no further shell processing. Arguments can contain any special characters.
Not sure why you’re seeing this behavior. Are you doing something with these file names before passing them to
mv
? Storing them in variables? Saving them to files? - Comment on mv *.jpg is complete bullshit. 8 months ago:
Which shell are you using? This does not happen in Bash, Zsh, or any modern shell I’m familiar with.
- Comment on Air: Where did that bring you? Back to me. 11 months ago:
Can you tell me more about your case and noise insulation? I’ve recently been unhappy with my PC’s noise level and I’m looking for upgrades.