News for hackers. Stuff that matters.
Re:Bash functions are better than I thought by sodapopcan on Sunday October 31, 2021 @03:16PM (#29059509)
My feeling is that it is about convenience when typing at the terminal. Having a unified language for both scripting and entering commands is quite convenient. Also, bare strings while typing at the terminal is very convenient! It would be really annoying if we always had to add quotes for string args when we're typing at the terminal:

  $ cat "file.txt"
...and I don't even know what options would look like... maybe:

  $ ls "*.txt", ["l", "a"]
I dunno... this would mean we'd probably need parens now for precedent-type concerns:

  $ ls("*.txt", ["l", "a"]) > "file.txt"
Anyway, that is why I understood that it's this way. I can't point to a resource about it, though.
Re:Bash functions are better than I thought by jandrese on Sunday October 31, 2021 @03:41PM (#29059734)
You look like you are just about to discover Powershell.
Re:Bash functions are better than I thought by psyclobe on Sunday October 31, 2021 @05:57PM (#29060843)
Powershell is how I instrument cross platform CI scripting, with the power of the module concept and manifess now you can write real powerful type safe apis that can run anywhere. It has its quirks though...
Re:Bash functions are better than I thought by joombaga on Sunday October 31, 2021 @08:25PM (#29061840)
Any gotchas with running the same scripts on Windows and Linux? I've been thinking about switching to PowerShell. Love it on Windows. Never tried it on Linux but I did try it on macOS a few years ago and remember some quirks. Currently a bash (over)user.
Re:Bash functions are better than I thought by psyclobe on Sunday October 31, 2021 @08:37PM (#29061914)
One gotcha is powershell core has some different apis then the 'windows powershell', best to deploy core on both systems to unify the api.

Also powershell has no support for automatically handling external shell commands that error, you must manually check $LASTEXITCODE (easily done with a custom invoke api that you use for everything).

Also well, some of the escaping in strings is really odd...

Re:Bash functions are better than I thought by pajko on Sunday October 31, 2021 @05:13PM (#29060500)
You have to add quotes in bash if the filename contains a space. Variables should also be quoted for the same reason, because their values might contain spaces. "${var}"
Re:Bash functions are better than I thought by dahfizz on Sunday October 31, 2021 @06:14PM (#29060973)
Only in a script. On the command line, tab expansion will escape any special characters in a filename.
Re:Bash functions are better than I thought by fragmede on Sunday October 31, 2021 @05:56PM (#29060840)
don't forget to handle filenames with newlines in them as well!
Re:Bash functions are better than I thought by fstrthnscnd on Sunday October 31, 2021 @06:44PM (#29061200)
> It would be really annoying if we always had to add quotes for string args when we're typing at the terminal

With bash (and I suspect with every other popular shells out there), it actually means something different. In your second example, if you don't use quotes, the shell will do the extensions, but if you do, the process will have to do it (and in the case of ls, it cannot).

In some case it's good to have the shell taking care of it, but sometimes (eg, when using 'find') it's not.

Re:Bash functions are better than I thought by sodapopcan on Sunday October 31, 2021 @07:08PM (#29061361)
My examples are a made-up idea of what a “real” programming language would look like in a shell, not actual bash.
Re:Bash functions are better than I thought by fstrthnscnd on Monday November 01, 2021 @06:07AM (#29064785)
Sorry, clearly my comment wasn't very helpful.

I was trying to point out that quoting parameters or not could bring a different meaning for a shell (as one could see it with Bash), with the implied consequence that one would have to carry over that nuance somehow to a shell where all parameters would have to be quoted.

Re:Bash functions are better than I thought by fooofw on Sunday October 31, 2021 @10:20PM (#29062452)
I feel like this comment is almost a kind of inverse of https://news.ycombinator.com/item?id=23424853 (which I remember to have found interesting).