-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
pkgs/stdenv/generic/setup.sh: lint with ShellCheck #351849
Conversation
pkgs/stdenv/generic/setup.sh
Outdated
if [[ ! -n "${nameref[@]}" && -n "$default" ]]; then | ||
if [[ -z "${nameref[*]-}" && -n "${default-}" ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We gotta be careful here, there was quite some discussion in #335666 around this part. Is this 100% the same as before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should remove the hyphens:
if [[ -z "${nameref[*]}" && -n "$default" ]]; then
As the Bash Reference Manual doesn't specify the behavior of [[ -n "${arr[@]}" ]]
, let's experiment with the command if [[ -n "${foo[@]}" ]]; then echo yes; else echo no; fi; unset foo
:
unset foo |
foo="" |
foo=" " |
foo=" hi" |
foo="hello hi" |
---|---|---|---|---|
no | no | yes | yes | yes |
foo=() |
foo=("") |
foo=("" "") |
foo=("" hi) |
foo=("hello" "hi") |
---|---|---|---|---|
no | no | yes | yes | yes |
According to the Bash Reference Manual,
Any element of an array may be referenced using ${name[subscript]}. ... If the word is double-quoted, ${name[*]} expands to a single word with the value of each array member separated by the first character of the IFS variable
This means the following conversion when the first character of the IFS variable is " "
:
foo=() |
foo=("") |
foo=("" "") |
foo=("" hi) |
foo=("hello" "hi") |
---|---|---|---|---|
"" |
"" |
" " |
" hi" |
"hello hi" |
It should be safe to say that [[ -n "${foo[@]}" ]]
behaves like [[ -n "$foo[*]" ]]
, but only the latter is specified in the Bash Reference Manual.
The behaviour of [[ -n/-z "${FOO[@]}" ]] is unspecified. Use [[ -n/-z "${FOO[*]-}" ]] instead
6c73c49
to
34ebbd6
Compare
This should be good despite the eval error, which is related to the target branch at that time. |
The behaviour of
[[ -n/-z "${FOO[@]}" ]]
is unspecified. Use[[ -n/-z "${FOO[*]-}" ]]
instead.Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.