1

The one-liner from mklement0 in this discussion on POSIX-compliant scripts and getting the full path. It's failing ShellCheck. Removing the space causes it to no longer work.
https://stackoverflow.com/questions/29832037/how-to-get-script-directory-in-posix-sh

dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) ^-- SC1007: Remove space after = if trying to assign a value (for empty string, use var='' ... ). 

Removing CDPATH= results in ShellCheck passing, and it still seems to work, but...

The CDPATH= prefix takes the place of > /dev/null in the original command: $CDPATH is set to a null string so as to ensure that cd never echoes anything.

Looks like it's needed. So, is there any way to make this pass ShellCheck? Or just ignore it?

1 Answer 1

2

Yes, you can specify a quoted empty value:

dir=$(CDPATH='' cd -- "$(dirname -- "$0")" && pwd) 

as suggested by ShellCheck:

(for empty string, use var='' ... )

1
  • Thanks for the clarification. I saw var=''..., and my brain processed that completely wrong. I need to update my terminal preferences. I clearly can't read it right! Commented Jun 16, 2022 at 13:18

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.