Skip to content

Style and shellchecks#13543

Closed
zimbatm wants to merge 4 commits intoNixOS:stagingfrom
zimbatm:style-and-shellchecks
Closed

Style and shellchecks#13543
zimbatm wants to merge 4 commits intoNixOS:stagingfrom
zimbatm:style-and-shellchecks

Conversation

@zimbatm
Copy link
Copy Markdown
Member

@zimbatm zimbatm commented Feb 28, 2016

Things done:
  • Tested using sandboxing (nix-build --option build-use-chroot true or nix.useChroot on NixOS)
  • Built on platform(s): NixOS / OSX / Linux
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

Replaces #13542

`--set FOO ""` is not strictly equivalent to `--unset FOO`. In the former case
the environment variable still exists with an empty string as a value.
@mention-bot
Copy link
Copy Markdown

By analyzing the blame information on this pull request, we identified @edolstra, @ttuegel and @nbp to be potential reviewers

@zimbatm
Copy link
Copy Markdown
Member Author

zimbatm commented Feb 28, 2016

@dezgeg I have never had the use for -v. In d844a10 you could also have used [[ -n $propagatedOutputs ]] or [[ -n "$propagatedOutputs" ]] for similar result.

@zimbatm zimbatm mentioned this pull request Feb 28, 2016
5 tasks
@dezgeg
Copy link
Copy Markdown
Contributor

dezgeg commented Feb 28, 2016

@zimbatm No, neither of those are correct. It's checking whether the variable is set, not for whether it's empty.

@zimbatm
Copy link
Copy Markdown
Member Author

zimbatm commented Feb 28, 2016

@dezgeg I misread, the reverse of -n is -z and works fine for me.

@dezgeg
Copy link
Copy Markdown
Contributor

dezgeg commented Feb 28, 2016

No.

Correct:

$ unset propagatedOutputs; if [ -z "${propagatedOutputs+1}" ]; then echo unset; else echo set; fi
unset
$ propagatedOutputs=""; if [ -z "${propagatedOutputs+1}" ]; then echo unset; else echo set; fi
set

Wrong:

$ propagatedOutputs=""; if [[ -z "$propagatedOutputs" ]]; then echo unset; else echo set; fi
unset
$ unset propagatedOutputs; if [[ -z "$propagatedOutputs" ]]; then echo unset; else echo set; fi
unset

@zimbatm
Copy link
Copy Markdown
Member Author

zimbatm commented Feb 28, 2016

Usually I treat the empty variable as unset. Otherwise it becomes hard to run bash scripts with set -u.

@dezgeg
Copy link
Copy Markdown
Contributor

dezgeg commented Feb 28, 2016

Well here you can't, which was the point.

@@ -1,86 +1,99 @@
#!bash
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That shebang doesn't conform to POSIX. The interpreter must be an absolute path.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And besides, there's no point in having a shebang because this script doesn't so anything. All it does is define functions, so it must necessarily be sourced. Doing "./make-wrapper.sh" makes no sense.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it's a hack so that ShellCheck and vim detect the proper shell dialect. Maybe there is a better way to do it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the shebang is pointless here. I guess running ShellCheck with "-s bash" would be better in this case. I certainly don't want a shebang that violates POSIX.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't bother me that much because in that context we only need internal compatibility but I understand, I'll remove it.

@zimbatm
Copy link
Copy Markdown
Member Author

zimbatm commented Feb 29, 2016

@dezgeg for the rare cases where you specifically need to check the existence of a variable I think that [[ -v varname ]] is better than [ -z "${varname+1}" ]. Hopefully future generations won't have to learn that that weird -z +1 hack.

@zimbatm
Copy link
Copy Markdown
Member Author

zimbatm commented Mar 6, 2016

Alright, abandoning this

@zimbatm zimbatm closed this Mar 6, 2016
@zimbatm zimbatm deleted the style-and-shellchecks branch March 6, 2016 19:50
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.

4 participants