Does Darwin/MacOS modify Bash?

非 Y 不嫁゛ 提交于 2019-12-01 18:44:39

问题


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. But do they tend to leave Bash and Bash built-ins alone? What about MacOS in particular?


回答1:


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.




回答2:


Apple use quite an old version of Bash, as they don't ship code that's licensed under GPL3. You can download the current version from Apple's open source site, and see that it at least claims to be vanilla Bash 3.2 (though obviously the Xcode project has been added).




回答3:


bash version 4 is not shipping on Darwin or MacOS Lion. so the mac does not support the improvements to the read command, etc which is unfortunate.

cygwin has bash 4.1.10



来源:https://stackoverflow.com/questions/10418616/does-darwin-macos-modify-bash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!