Tuesday, April 5, 2022

Using shellcheck With BBEdit

Armin Briegel:

Once you have the shellcheck command installed, you can also invoke from within BBEdit: When you have a script open in BBEdit, verify that the script is recognized as a ‘Unix shell script.’ Then you can select ‘Check Syntax…’ from the ‘#!’ menu (keyboard shortcut ⌘-K). This will open a second window with all the issues shellcheck has found.

Unfortunately, given that Apple is phasing out bash, it doesn’t work with zsh.

Previously:

Update (2022-04-13): Matt Sephton:

zsh -n $FILENAME and/or zsh -x $FILENAME (non_exec and debug mode respectively) are a reasonable workaround. Not shellcheck good but workable.

2 Comments RSS · Twitter

So true. And it doesn't seem like they plan to support zsh anytime soon (https://github.com/koalaman/shellcheck/issues/809).

I've been using the following workaround using zsh's Bash emulation mode:

#!/bin/zsh
# shellcheck shell=bash
emulate -LR bash

I really doubt Apple is going to totally remove bash from macOS entirely, there are too many scripts out there whose first line is `#!/bin/bash` ... all they've changed is the *default* login shell that you type into. Existing (or new) scripts which have `#!/bin/bash` as the first line will continue to work as they always have.

Of course, they are still shipping with an outdated *version* of bash. This will probably never change. Apple hasn't explained why, but the community consensus is that it's because bash changed their license from GPLv2 to GPLv3, which includes some clauses about software patents that Apple's legal department is probably not comfortable with.

Anyway.

You can change your shell to bash like so:

```
chsh -s /bin/bash
```

And you can make it stop nagging you to switch to zsh by adding this to your `$HOME/.bashrc` file:

```
export BASH_SILENCE_DEPRECATION_WARNING=1
```

Leave a Comment