Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] add support for zsh shell #2648

Closed
superbonaci opened this issue Dec 29, 2022 · 6 comments
Closed

[Feature request] add support for zsh shell #2648

superbonaci opened this issue Dec 29, 2022 · 6 comments

Comments

@superbonaci
Copy link

superbonaci commented Dec 29, 2022

shellcheck version 0.9.0
Add support for shellcheck --shell=zsh since is highly used. Comes by default in Kali linux and macOS (zsh 5.8.1).

Example code:

#!/bin/bash
SOMETEXT=""
NUMBER="0"
if [ "$SOMETEXT" == "" ] && [ "$NUMBER" -eq 0 ]; then echo "match"; else echo "no match"; fi

zsh will complain while bashwill work normally

$ bash check.sh
match

$ zsh check.sh
../check.sh.sh:4: = not found

The fix for both is this:

#!/bin/bash
SOMETEXT=""
NUMBER="0"
if [ "$SOMETEXT" = "" ] && [ "$NUMBER" -eq 0 ]; then echo "match"; else echo "no match"; fi
@superbonaci
Copy link
Author

zshalso fails here:

#!/bin/bash
SOMETEXT=""
NUMBER="0"
if [ "$SOMETEXT" = "" ] && [ "$NUMBER" -eq 0 ]; then echo "match"; else echo "no match"; fi

MONEY="2"
if [ "$MONEY" -eq $(("$NUMBER" + 2)) ]; then echo "match"; else echo "no match"; fi
$ zsh check.sh
match
check.sh:7: bad math expression: illegal character: "

$ bash check.sh
match
match

@superbonaci superbonaci changed the title [Feature request] ass support for zsh shell [Feature request] add support for zsh shell Dec 31, 2022
@FranklinYu
Copy link

FranklinYu commented Jan 1, 2023

  1. Double bracket ([[ ]]) in Zsh allows double dash. IMO, if ShellCheck is to support Zsh, it should simply recommend double bracket.
  2. If the executable is supposed to run under multi-shell, then it is probably a shell library that people source in their shell (e.g. nvm), instead of some executable script that people execute under a sub-shell (e.g. ./configure). In this case I recommend no shebang (since the shebang is misleading anyway).
  3. Best practice in Bash doesn’t mean best practice in Zsh. Amount of work might not be trivial to add rules for Zsh.

@wakco
Copy link

wakco commented Jan 6, 2023

Apple deprecated their inclusion of bash in 2019, as newer versions of bash than those used by Apple are GPLv3, while zsh is not. As such zsh has been the default on macOS since macOS 10.15 Catalina (released 2019), which https://support.apple.com/HT208050 confirms.

Sooner or later Apple will remove bash from macOS, so having a tool like ShellCheck be ready for when that happens, would be greatly appreciated.

(typo fixed, thanks @TinCanTech)

@TinCanTech
Copy link

having a tool like spellcheck be ready

That needs a shellcheck [SCnnnn] number.

@superbonaci
Copy link
Author

Some information (2019 posts):

@brother
Copy link
Collaborator

brother commented Jan 12, 2023

This is a dupe of #809 .

@brother brother closed this as completed Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants