Does Darwin/MacOS modify Bash?

后端 未结 3 1732
礼貌的吻别
礼貌的吻别 2021-01-19 18:56

I\'m wondering about the portability of Bash scripts that use Bash built-in commands.

I understand that each flavor of UNIX tends to modify various UNIX utilities. B

3条回答
  •  被撕碎了的回忆
    2021-01-19 19:14

    As far as I know, bash is unmodified on Mac OS X (aside from minor tweaks required to make it compile; you can review the source on http://opensource.apple.com/), and scripts should be quite portable.

    As Graham Lee & Gordon Davisson point out, Mac OS X ships with older versions and there are differences between supported versions. Bash 4 has associative arrays and other changes. Bash 3 includes regular expression matching (and probably others that I haven't searched for). Can't remember the Bash 2 differences, maybe some bracketing/conditional test differences?

    Mac OS X 10.7.x Lion includes Bash 3.2.x. I don't recall the exact versions off the top of my head, but Mac OS X 10.6.x Snow Leopard & 10.5.x Leopard include Bash 3.x. Mac OS X 10.4.x Tiger and earlier used Bash 2.0.5. So, you'll definitely run into differences between what's supported by default.

    Naturally, beyond the differences between feature sets & built-ins for the different bash versions on Mac OS X , you'll also find differences in other tools. For example, there are getopt issues on Mac OS X (spaces, which are frequently found in Mac OS X directory/file paths, are not supported in arguments; the built-in getopts in newer bash versions can help with this, but may not be available in older versions). Naturally, there will be other tools that have different functionalities or syntaxes as well.

    I'm definitely not an expert bash developer, but I've written a number of Mac OS X-specific scripts that support various releases. See my Regular Expressions in Bash and Alternatives article for discussion of the 2.x vs 3.x regular expression features and workarounds. Or, some of my bash scripts which have taken Mac OS X into heavy consideration: tools-osx & bash_stub.

提交回复
热议问题