Closed ashthespy closed 3 years ago
@xipmix please confirm if this achieves what you would like to do, so we merge it
I went down a similar road with a separate function but didn't include the BUILD check, because I guess I thought that specifying a bad device was handled already... I'm a bit surprised the -n $DEVICE
check (and -n $BUILD
) works with the variable unset, I would have written -n "$DEVICE"
. But clearly it does work, so from my perspective, merge away.
Good point, will quote it just to be consistent..
EDIT:
Just did a little coffee time reading as I was curious why it was working as expected -- in [bash [[
doesn't need to be quoted in most cases](https://www.gnu.org/software/bash/manual/bash.html#index-_005b_005b), and will expand most without quoting. http://mywiki.wooledge.org/BashFAQ/031
#!/usr/bin/env bash
var="foo bar"
# unset
set=''
[ $var == "foo bar" ] && echo "[ var == : true"
[[ $var == "foo bar" ]] && echo "[[ var == : true"
[ -n $unset ] && echo "[ notnull: unset: true"
[[ -n $unset ]] && echo "[[ notnull: unset: true"
[ -n $set ] && echo "[ notnull: set: true"
[[ -n $set ]] && echo "[[ notnull: set: true"
GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
$ bash main.sh
main.sh: line 6: [: too many arguments
[[ var == : true
[ notnull: unset: true
[ notnull: set: true
exit status 1
Added the quotes for good measure and to be consistent.. RTM from my side!
This should cover things as described by @xipmix -- or did I miss something?
And this beauty that I actually ran :-D