News for hackers. Stuff that matters.
Re:Filenames and Pathnames in Shell: How to Do It Correctly by lenkite on Tuesday June 20, 2023 @02:29AM (#36400441)
This is the reason its better to use a "Real Programming Language" leveraging libraries to do this job instead of a shell script. A ludicrous number of things to keep in mind for simple filenames and pathnames.
Re:Filenames and Pathnames in Shell: How to Do It Correctly by atoav on Tuesday June 20, 2023 @02:35AM (#36400475)
* * *
Re:Filenames and Pathnames in Shell: How to Do It Correctly by meinheld111 on Tuesday June 20, 2023 @03:56AM (#36400953)
Messing with IFS can also solve a lot of problems
Re:Filenames and Pathnames in Shell: How to Do It Correctly by diegocg on Tuesday June 20, 2023 @03:06AM (#36400661)
Or just use a sane shell (eg. the oil shell https://www.oilshell.org/blog/2020/10/osh-features.html#elim..., fish) where handling pathnames with spaces, etc. is not a problem and doesn't require arcane quoting knowledge or linters.

The only reason why this is an issue is that people insists in using bash in the name of backwards compatibility. It's about time people start considering moving away from bash - its design is broken and the efforts and time it takes to write safe bash shells might not be worth it.

Re:Filenames and Pathnames in Shell: How to Do It Correctly by meinheld111 on Tuesday June 20, 2023 @03:55AM (#36400948)
Brokenness is really a tradeof.

Imho using oil/fish/etc trades unfavorable because of network effects but it is perfectly acceptable choice in many circumstances

Re:Filenames and Pathnames in Shell: How to Do It Correctly by planede on Tuesday June 20, 2023 @04:45AM (#36401304)
I don't disagree, but only some of the rules are really about the shell itself. A significant part of the problem is the stringly-typed interface of exec. Avoiding passing filenames starting with "-" has little to do with shells.
Re:Filenames and Pathnames in Shell: How to Do It Correctly by IshKebab on Tuesday June 20, 2023 @04:57AM (#36401394)
The only real reason to use Bash in the first place is that people will probably have it installed already (assuming you don't care about the most popular desktop OS in the world).

If you're going to add a dependency you may as well just use a "real" language at that point.

I've been using Deno for "shell scripts" for a while and it's great. My only complaint is that `deno run` prints annoying "a new version of Demo is available" messages which it very clearly shouldn't. Hopefully they'll fix that.

Re:Filenames and Pathnames in Shell: How to Do It Correctly by maleldil on Tuesday June 20, 2023 @07:49AM (#36402701)
> If you're going to add a dependency you may as well just use a "real" language at that point.

Not necessarily. It's still easier to manipulate shell programs in fish[0] than it is in Python since fish was made explicitly for that. Calling external programs, using pipes, process substitution, etc. are easier in a "proper" shell language.

[0] Or any bash alternative of your choice: nushell, oils, xonsh, elvish, etc.

Re:Filenames and Pathnames in Shell: How to Do It Correctly by harrisi on Tuesday June 20, 2023 @11:17AM (#36405223)
I don't know if they're planning on changing that, but `-q|--quiet` will suppress this. It just sets the log level to error, and the new version message is info level.