Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 47
    That's a BIG difference, portability... I see too many answers which simply do NOT work on (older) production systems, and also many with options that only work on linux. At least, warn that this is not the most portable way... It could be downright dangerous (asking someone to tar cf - /some/thing | ssh user@desthost "cd destinationdir && tar xf - " without warning them to first double-check if the version of tar on desthost will get rid of the "/" could lead to disasters in some cases...). For ex: if use a function tar { #a safe tar with safety checks ... } and sh ignores it, ... Commented Apr 26, 2013 at 15:51
  • 2
    @OlivierDulac I would add that scripts that assume sh recognizes the function keyword -- and, in general, that assume common but nonstandard features that shells like ksh and bash offer -- will also often not work on newer production systems, even if they worked on older releases of the same OS. bash still provides sh on many GNU/Linux systems, but some popular distros have switched to having sh as a symlink to dash (the Debian Almquist SHell) to improve performance. This includes Debian and Ubuntu. Commented Apr 11, 2018 at 12:43
  • 8
    Without elaborating how exactly it's "more portable", the answer is not useful. Commented Mar 22, 2019 at 13:21
  • 4
    Portability is no argument nowadays where the industry is using bash or an equivalent shell in >99.9% of all environments. It boils down to readability and there is two sides: some people say "function" makes it obvious, people who learnt it from the posix standards or other shells will say braces are the more obvious style. In the end, choose one within your group or company and stick to it. Commented Aug 26, 2019 at 14:46