Skip to content

SC2164: suppress when cd is the final command in a function - #3426

Merged
koalaman merged 2 commits into
koalaman:masterfrom
notpeter:sc2164-false-positive
May 16, 2026
Merged

SC2164: suppress when cd is the final command in a function #3426
koalaman merged 2 commits into
koalaman:masterfrom
notpeter:sc2164-false-positive

Conversation

@notpeter

@notpeter notpeter commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Fixes: #2474

When cd is the last command in a function,

#!/bin/bash

foo() {
  cd /abc
}

Shellcheck currently triggers SC2164 and suggest using cd /abc || return even though that is no safer than the existing code.

AI disclosure: I used Codex to assist in implementing this PR.

@koalaman

koalaman commented Apr 4, 2026

Copy link
Copy Markdown
Owner

Definitely a valid complaint, but the added test does not pass

@notpeter

notpeter commented Apr 8, 2026

Copy link
Copy Markdown
Contributor Author

Adjusted so prop_checkUncheckedCdInFunction1 test case passes and this no longer warns:

#!/bin/bash
foo() {
  cd /abc
}

@koalaman
koalaman merged commit 1b59697 into koalaman:master May 16, 2026
16 checks passed
@koalaman

Copy link
Copy Markdown
Owner

Thanks!

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

Successfully merging this pull request may close these issues.

SC2164 false positive with cd at end of shell function

2 participants