-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
allow the expansion of ~ when sourcing files #507
Comments
Why |
I would be open to that too, but the same problem exists. Shellcheck does not expand |
Ah. Sounds like shellcheck should possibly understand shellcheck not assuming |
Sounds reasonable, but I do hope that expanding both Also, I've realized that not all of the cases where I use shellcheck are in a shell instance (like the atom plugin, so env vars would not be available directly. I do think that populating the "environment" would be important. |
That being said I'm not sure using either of those in scripts is all that good of an idea. Finding the location of the currently executing script and using that to find bundled scripts seems like a more robust plan to me (and would be something that shellcheck could, I think, easily detect the common idioms for and support but that's not my decision). |
All good points. I do believe that shellcheck already warns about My primary use case for using either of these is related to my dotfiles where many of the scripts need to be relative to the home directory. However, I version all of the scripts in a separate directory and symlink them from there to the proper location. Because of that, referencing them relative to the home directory definitely simplifies things. |
Yes, tilde expansion is implicitly quoted and not subject to field splitting and pathname expansion. From the spec:
And yeah, I see why you want to use |
It would be both reasonable and convenient, and However, to postpone any decisions about whether to use shellcheck's HOME or the script's HOME or the user's home dir or whether to support ~foo and ~+ and ~- and whether to account for PATH with Maybe you can add an example config in the script's source dir and use that, or run shellcheck from the dir with the include files you want? |
I think the change to get the other error reporting was an appropriate step, but I don't understand what you mention about a config? I found some other issues mentioning a Could you expand on how I could do what you are referring to? |
any chance there is a better recommendation than simply disabling the |
@travi Did you ever find a nice way around this? I also want to use shellcheck with my dotfiles (and so refer to things relative to my home). |
I don't believe so, but it has been a bit of time since I've tried very hard. It looks like i have a mix of switching Interesting timing with your question though, I also got a notification about a thread I've been following for |
SC2148 .bash_profile and .bashrc shouldn't containing shebang See https://unix.stackexchange.com/questions/88728/why-no-shebang-in-bashrc-bash-profile SC1090 koalaman/shellcheck#507
SC2148 .bash_profile and .bashrc shouldn't containing shebang See https://unix.stackexchange.com/questions/88728/why-no-shebang-in-bashrc-bash-profile SC1090 koalaman/shellcheck#507
SC2148 .bash_profile and .bashrc shouldn't containing shebang See https://unix.stackexchange.com/questions/88728/why-no-shebang-in-bashrc-bash-profile SC1090 koalaman/shellcheck#507
Ignore SC1090: ShellCheck can't follow non-constant source. Use a directive to specify location. https://www.shellcheck.net/wiki/SC1090 See the following discussion for why SC1090 is disabled and not fixed: koalaman/shellcheck#507
Well, an example file could be the Ubuntu's default ...
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
... We can freely argue semantics; but I'd like for it to be "clean cut and working out of the box" without (much) additional changes/configs/lintings. |
Fix SC2140 Fix SC2140: Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A\"B\"C"? https://www.shellcheck.net/wiki/SC2140 Ignore SC2139 Ignore SC2139: This expands when defined, not when used. Consider escaping. https://www.shellcheck.net/wiki/SC2139 Fix SC2046 Fix SC2046: Quote this to prevent word splitting. https://www.shellcheck.net/wiki/SC2046 Fix SC2181 Fix SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?. https://www.shellcheck.net/wiki/SC2181 Fix SC2199 Fix SC2199: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @). https://www.shellcheck.net/wiki/SC2199 Fix SC2124 Fix SC2124: Assigning an array to a string! Assign as array, or use * instead of @ to concatenate. https://www.shellcheck.net/wiki/SC2124 Fix SC1018 Fix SC1018: This is a unicode non-breaking space. Delete and retype it. https://www.shellcheck.net/wiki/SC1018 Fix SC2155 Fix SC2155: Declare and assign separately to avoid masking return values. https://www.shellcheck.net/wiki/SC2155 Ignore SC2154 Ignore SC2154: yellow is referenced but not assigned. https://www.shellcheck.net/wiki/SC2154 Ignore SC2034 Ignore SC2034: foo appears unused. Verify use (or export if used externally). https://www.shellcheck.net/wiki/SC2034 Fix SC2091 Fix SC2091: Remove surrounding $() to avoid executing output (or use eval if intentional). https://www.shellcheck.net/wiki/SC2091 Fix SC2162 Fix SC2162: read without -r will mangle backslashes. https://www.shellcheck.net/wiki/SC2162 Fix SC2166 Fix SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined. https://www.shellcheck.net/wiki/SC2166 Ignore SC1090 Ignore SC1090: ShellCheck can't follow non-constant source. Use a directive to specify location. https://www.shellcheck.net/wiki/SC1090 See the following discussion for why SC1090 is disabled and not fixed: koalaman/shellcheck#507 Fix SC2128 Fix SC2128: Expanding an array without an index only gives the first element. https://www.shellcheck.net/wiki/SC2128 Fix SC2164 Fix SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. https://www.shellcheck.net/wiki/SC2164 Fix SC2197 Fix SC2197: fgrep is non-standard and deprecated. Use grep -F instead. https://www.shellcheck.net/wiki/SC2197
Fix SC2140 Fix SC2140: Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A\"B\"C"? https://www.shellcheck.net/wiki/SC2140 Ignore SC2139 Ignore SC2139: This expands when defined, not when used. Consider escaping. https://www.shellcheck.net/wiki/SC2139 Fix SC2046 Fix SC2046: Quote this to prevent word splitting. https://www.shellcheck.net/wiki/SC2046 Fix SC2181 Fix SC2181: Check exit code directly with e.g. 'if mycmd;', not indirectly with $?. https://www.shellcheck.net/wiki/SC2181 Fix SC2199 Fix SC2199: Arrays implicitly concatenate in [[ ]]. Use a loop (or explicit * instead of @). https://www.shellcheck.net/wiki/SC2199 Fix SC2124 Fix SC2124: Assigning an array to a string! Assign as array, or use * instead of @ to concatenate. https://www.shellcheck.net/wiki/SC2124 Fix SC1018 Fix SC1018: This is a unicode non-breaking space. Delete and retype it. https://www.shellcheck.net/wiki/SC1018 Fix SC2155 Fix SC2155: Declare and assign separately to avoid masking return values. https://www.shellcheck.net/wiki/SC2155 Ignore SC2154 Ignore SC2154: yellow is referenced but not assigned. https://www.shellcheck.net/wiki/SC2154 Ignore SC2034 Ignore SC2034: foo appears unused. Verify use (or export if used externally). https://www.shellcheck.net/wiki/SC2034 Fix SC2091 Fix SC2091: Remove surrounding $() to avoid executing output (or use eval if intentional). https://www.shellcheck.net/wiki/SC2091 Fix SC2162 Fix SC2162: read without -r will mangle backslashes. https://www.shellcheck.net/wiki/SC2162 Fix SC2166 Fix SC2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined. https://www.shellcheck.net/wiki/SC2166 Ignore SC1090 Ignore SC1090: ShellCheck can't follow non-constant source. Use a directive to specify location. https://www.shellcheck.net/wiki/SC1090 See the following discussion for why SC1090 is disabled and not fixed: koalaman/shellcheck#507 Fix SC2128 Fix SC2128: Expanding an array without an index only gives the first element. https://www.shellcheck.net/wiki/SC2128 Fix SC2164 Fix SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. https://www.shellcheck.net/wiki/SC2164 Fix SC2197 Fix SC2197: fgrep is non-standard and deprecated. Use grep -F instead. https://www.shellcheck.net/wiki/SC2197
In scripts that I use across multiple systems, I use
~
when referencing my home directory since it is at a different location on each system. However, recent versions have been giving me warnings related toSC1091
even when running asshellcheck -x
for files that do exist.Would it be reasonable to enable shellcheck to follow paths that include
~
like this?The text was updated successfully, but these errors were encountered: