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.

Required fields*

11
  • 2
    Add #!/usr/bin/env bash to the top of the file and you're good. Seriously. Trying to write actually portable shell scripts is an exercise in pain and futility, IMO, and maintainers are going to absolutely hate the result. Or you could ./do-the-thing-in-most-shells.sh || ./do-the-thing-in-ksh.ksh. Commented Sep 8, 2019 at 18:59
  • 1
    You can often use a subshell instead. Commented Sep 8, 2019 at 19:22
  • 4
    Just save the value of IFS and restore it afterwards. Stick to POSIX features if you want portability. Commented Sep 8, 2019 at 19:37
  • @Mikel Subshells may be an order of magnitude slower (Try it online!) Commented Sep 9, 2019 at 23:12
  • @Wildcard It becomes quite ugly to cover an originally unset IFS. Commented Sep 9, 2019 at 23:15