Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Bash (Unix shell)
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Portability with POSIX === Invoking Bash with the <code>--posix</code> option or stating <code>set -o posix</code> in a script causes Bash to conform very closely with the [[Posix#POSIX.2|POSIX 1003.2 standard]].<ref name="tldp">{{Cite web |last=Mendel Cooper |title=Portability Issues |url=http://tldp.org/LDP/abs/html/portabilityissues.html |url-status=live |archive-url=https://web.archive.org/web/20120127105451/http://tldp.org/LDP/abs/html/portabilityissues.html |archive-date=January 27, 2012 |access-date=January 26, 2012 |website=The Linux Documentation Project |publisher=ibiblio.org }}</ref> Bash shell scripts intended for [[portability (computer science)|portability]] should take into account at least the POSIX shell standard. Some bash features not found in POSIX are:<ref name="tldp" /><ref name="deb">{{Cite web |title=10. Files |url=https://www.debian.org/doc/debian-policy/ch-files.html#scripts |url-status=live |archive-url=https://web.archive.org/web/20200512050159/https://www.debian.org/doc/debian-policy/ch-files.html#scripts |archive-date=May 12, 2020 |access-date=May 11, 2020 |website=Debian Policy Manual v4.5.0.2 }}</ref> {{div col start}} * Certain extended invocation options * Brace expansion * Arrays and associative arrays * The double bracket {{code| [[...]] }} extended test construct and its regex matching * The double-parentheses arithmetic-evaluation construct (only {{code|(( ... ))}}; {{code|$(( ... ))}} is POSIX) * Certain string-manipulation operations in parameter expansion * {{code|local}} for scoped variables * Process substitution * Bash-specific builtins * [[Coprocess]]es * $EPOCHSECONDS and $EPOCHREALTIME variables<ref>{{Cite web |title=How To Format Date And Time In Linux, MacOS, And Bash? |url=https://www.shell-tips.com/linux/how-to-format-date-and-time-in-linux-macos-and-bash/#using-the-gnu-date-command-line |url-status=live |archive-url=https://web.archive.org/web/20200603230615/https://www.shell-tips.com/linux/how-to-format-date-and-time-in-linux-macos-and-bash/#using-the-gnu-date-command-line |archive-date=June 3, 2020 |access-date=June 3, 2020 |website=Shell Tips! }}</ref> {{div col end}} If a piece of code uses such a feature, it is called a "bashism" β a problem for portable use. Debian's {{code|checkbashisms}} and Vidar Holen's {{code|shellcheck}} can be used to make sure that a script does not contain these parts.<ref name="checkbashisms, ManKier man page">{{man|1|checkbashisms|ManKier}}</ref><ref name="shellcheck, ManKier man page">{{man|1|shellcheck|ManKier}}</ref> The list varies depending on the actual target shell: Debian's policy allows some extensions in their scripts (as they are in the [[Almquist shell#Dash|dash]] shell),<ref name=deb/> while a script intending to support pre-POSIX Bourne shells, like [[autoconf]]'s {{code|configure}}, are even more limited in the features they can use.<ref>{{Cite web |title=Portable Shell |url=https://www.gnu.org/software/autoconf/manual/html_node/Portable-Shell.html |url-status=live |archive-url=https://web.archive.org/web/20210302212413/https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.70/html_node/Portable-Shell.html |archive-date=March 2, 2021 |access-date=20 January 2020 |website=Autoconf }}</ref> <!-- === Comments === === Word Splitting & Quoting === '''+++ Backslash <code>\</code>''' '''+++ Double Quotes <code>"..."</code>''' '''+++ Single Quotes <code>'...'</code>''' '''+++ ANSI-C Quoting <code>$'...'</code>''' -->
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Bash (Unix shell)
(section)
Add topic