News for hackers. Stuff that matters.
Re:Something about functions in Bash (2017) by HerrMonnezza on Thursday July 05, 2018 @03:18PM (#17465987)
Nitpick: although the linked page states that defining functions as compund commands is a `bash` feature, it is actually in the POSIX `sh` standard [1] so it should work with any POSIX-compliant shell.

[1]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3...

That said, I'm curious what are the nifty tricks that one can do by using functions as "aliases" for compound commands -- I cannot see much of a difference between `function sleep1 () { while true; do "$@"; sleep 1; done; }` and the similar definition without the curly braces. Only once in my life I have had to use the `function foo () ( ... )` syntax (i.e., using subshell instead of normal `{ ... }` grouping).

Re:Something about functions in Bash (2017) by ben509 on Thursday July 05, 2018 @06:40PM (#17467474)
The subshell syntax is great for:

    ( cd some_directory
      do_a_thing_here )
... instead of all the pushd popd nonsense, and so much easier to follow.

You can also do this:

    ( set -e
      bail_from_this
      if_anything_fails ) < redirect || echo 'Something went wrong here, carrying on...'
And that won't set -e in your outer shell. You can also set -v to see what's being run just for those commands.

As far as writing functions without braces, I don't. It doesn't do anything useful, it's magical and weird to bash n00bs, and when you have to add a command you'll wind up adding the braces then.

The reason bourne shells have that is because the shell's raison d'etre is composing processes, so it makes sense that compound statements are simply processes themselves. (Maybe process is the wrong term here...) To expose that in the syntax, though, is just being overly clever, and it's more obvious now that people find it confusing.

Re:Something about functions in Bash (2017) by frou_dh on Thursday July 05, 2018 @04:13PM (#17466408)
For those who've never looked at the POSIX docs, bookmark this:

http://shellhaters.org

...which is a great jumping off point to casually read a bit of them now and again.

Re:Something about functions in Bash (2017) by schoen on Thursday July 05, 2018 @03:23PM (#17466036)
I'm always amazed at how many Unix features I assume are GNUisms or bashisms that turn out to be in POSIX and be much more portable than I've expected!
Re:Something about functions in Bash (2017) by webreac on Thursday July 05, 2018 @04:37PM (#17466610)
I'm always amazed at how scripts intented to use only POSIX features become buggy when dash is used instead of bash.
Re:Something about functions in Bash (2017) by yjftsjthsd-h on Thursday July 05, 2018 @08:36PM (#17468063)
Yeah, for anything that I want to be portable, I explicitly run it with bash, dash, mksh, and heirloom sh. I figure that if it works in all of those, then the result is either truly portable... or nobody will ever notice:)

It also should really help that Debian, IIRC, actually sets /bin/sh to dash by default?