3 ms·
This is awesome. Question: [[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]] Is it not safe to leave off the double quotes here, because it is inside [[
by gkfasdfasdf 6y ago
This is awesome. Question:
[[ -z "${NO_COLOR-}" ]] && [[ "${TERM-}" != "dumb" ]]
Is it not safe to leave off the double quotes here, because it is inside [[ ]] ?
- Lt_Riza_Hawkeye 6y agoNo. I'm not sure what the "-" is doing in "${TERM-}", but if $TERM was for example set to "-z stringhere" then that would be interpreted as two arguments to "[[" instead of one, and would ensure that it always returns false, for example
- vbernat 6y agoThe "-" is here to not error when the variable does not exist (as the topmost set is configured to trigger error on unset variables). It is meant to substitute the (empty) string on the right if the left variable does not exist.
- ben509 6y agoThere's normally no need for ${var-} to get default values, and you can put && inside. I'd write that as: [[ -z $NO_COLOR && $TERM != dumb ]] As another comment pointed out, they're erroring on unset values. I don't think the line noise is worth it, but it will catch spelling mistakes, I guess.