DevTools Logo

Bash POSIX Portability Checker

Bash POSIX Portability Checker

Find common Bashisms and make shell scripts portable. The script is only read as text and never executed.

Runs in your browser
Try an example

Script input

Results

Paste a script to check it

Results update as you type. Nothing leaves your browser.

About

A deterministic, quote-aware line and token scanner for common Bashisms including conditionals, arrays, arithmetic commands, functions, local variables, source, case modification, and echo options. No script leaves your device.

Examples

Double-bracket conditional

Input
checkBashPosixPortability("if [[ $x == y ]]; then\n  echo hi\nfi")
Output
[{ line: 1, bashism: "[[ ]] conditional", suggestion: "Use [ ... ] ..." }]

The [[ token survives quote-stripping, so line 1 is flagged with a bracket-test rewrite.

Quoted lookalike ignored

Input
checkBashPosixPortability("printf '%s' '[[ not code ]]'")
Output
{ findings: [], score: 100 }

Single-quoted text is removed before testing, so the [[ inside quotes is not code.

About this tool

Bash POSIX Portability Checker scans shell scripts with checkBashPosixPortability(script) (alias analyzeBashScript): each line is stripped to code-only text (single/double quotes and # comments removed, ${...} preserved inside double quotes) and tested against twelve Bashism rules.

Rules cover [[ ]], (( )), array assignment/expansion, == comparisons, += assignment, the function keyword, ${var^^} case modification, local, source, echo -e/-n, and $'...' quoting — every hit records a 1-based line, the Bashism name, and a POSIX rewrite suggestion.

Scoring is deterministic: zero findings score 100, otherwise 100 minus findings-per-line times 20 (floored at 0), with the line count of the script returned alongside.

How to use this tool

  1. Paste the script

    Pass the full script text — shebang included — to checkBashPosixPortability.

  2. Read findings

    Each finding names the Bashism, its line, and the POSIX suggestion to apply.

  3. Aim for 100

    Rewrite flagged lines ([ ... ], printf, . file) until findings empty out and score returns to 100.

Use cases

Porting scripts to dash

Find every Bash-only construct before switching #!/bin/sh to a minimal POSIX shell.

Reviewing install scripts

Catch +=, arrays, and source in cross-platform setup scripts during code review.

Teaching POSIX shell

Show the suggested rewrite for each Bashism as a portable-shell lesson.

Common mistakes

Mistake:Assuming quoted examples are checked.

Fix:Single/double-quoted text and # comments are stripped first — only real code is tested.

Mistake:Using source or == in #!/bin/sh scripts.

Fix:Use the dot command (. file) and single = for comparisons; both have dedicated rules.

Frequently asked questions

What does this tool do?

It scans shell scripts with checkBashPosixPortability against twelve Bashism rules ([[ ]], (( )), arrays, ==, +=, function, case modification, local, source, echo flags, $'...') and returns line-tagged findings with POSIX suggestions plus a 0–100 score.

How is the score computed?

Zero findings score 100; otherwise 100 minus findings-per-line times 20, floored at 0.

Is my script uploaded or stored?

No. Quote-aware line scanning and scoring run entirely in your browser.

Why was quoted code ignored, or += flagged?

Single/double-quoted text and # comments are stripped before testing so examples like '[[ ]]' never flag, while real code such as path+=/bin matches the += rule with a POSIX concatenation suggestion.

References & standards