pkgs/stdenv/generic/setup.sh: lint with ShellCheck#351849
pkgs/stdenv/generic/setup.sh: lint with ShellCheck#351849philiptaron merged 1 commit intoNixOS:stagingfrom
Conversation
pkgs/stdenv/generic/setup.sh
Outdated
There was a problem hiding this comment.
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.
I should remove the hyphens:
if [[ -z "${nameref[*]}" && -n "$default" ]]; thenAs 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 = relaxedsandbox = truenix-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.