envsubst icon indicating copy to clipboard operation
envsubst copied to clipboard

${var:+FOO} mishandles empty vars

Open jwilk opened this issue 2 years ago • 1 comments

$ export empty=''
$ echo '[${empty:+FOO}]' | envsubst 
[FOO]

This is not what shell does:

$ echo "[${empty:+FOO}]"
[]

jwilk avatar Mar 21 '23 17:03 jwilk

Still incorrectly implemented in v1.4.3. Let's imagine to have a true/false flag based on if another env var is empty or not:

$ export NUM=123 && echo 'enabled: ${NUM:-false}${NUM:+true}' | ./envsubst
enabled: 123true
$ export NUM= && echo 'enabled: ${NUM:-false}${NUM:+true}' | ./envsubst
enabled: falsetrue

gw0 avatar Mar 12 '25 11:03 gw0