cfeard wrote:
by the way, I wonder why they use the notation : [[ -z "${VAR:-}" ]] in Fedora scripts.
Is there an explanation why [[ -z "$VAR" ]] would not suffice ?
It's used to avoid having an error because of the
nounset feature possibly enabled. ( «
help set » )
See the example below.
Code:
$ [[ -z "$x" ]] && echo x is empty
x is empty
$ set -u
$ [[ -z "$x" ]] && echo x is empty
bash4.2: x: unbound variable
$ [[ -z "${x:-}" ]] && echo x is empty
x is empty
Also, quoting the LHS in the
[[ ...
]] syntax isn't needed, and you can use
! instead of
-z.
________
cfeard wrote:
well staying with bash is not always the best solution (bc is not bash for instance)
awk is terribly fast (try it for index (or create_user_list) for instance - about ten times
faster than bash - and the gain is greater the longer the string)
it's also true for the builtin bash gsub mechanism ${var//<str1>/<str2>} : it becomes
unusable for long strings (execution time grows exponentially)
I agree, but it's meant to be a
bash(1) library...
In my opinion, the goal is to use the fewest external programs.
I used
bc(1) because it supports floating-point numbers, whereas
bash(1) does not,
and
cat(1) because the implementation of the task would be really too slow.