0

What does the ending +x mean in the BUILD_ENV_IMAGE+x of below script?

if [[ -z "${BUILD_ENV_IMAGE+x}" ]]; then
    BUILD_ENV_IMAGE="${CI_CONTAINERS_REGISTRY}/build-env:${CI_CONTAINERS_BASE_TAG}-gcc11"
fi

I am not sure if it is bash or sh specific. So I add both tags.

ADD 1 -- 2:10 PM 1/14/2023

A sample

# var is set to null
var=


# check if var is unset or null
echo ${var:+literal_out_put} abc

# only check if var is unset
echo ${var+literal_out_put}

if [[ -z ${var+literal_out_put} ]];
then 
    echo var is unset;
else
    echo var = $var
fi

Output:

abc
literal_out_put
var =

Table from https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02

enter image description here

smwikipedia
  • 61,609
  • 92
  • 309
  • 482
  • See https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html – Shawn Jan 14 '23 at 04:21
  • 1
    @Shawn Thanks. I checked some similar ref before. But it only talks about `:+`. Not `+`. – smwikipedia Jan 14 '23 at 05:04
  • 1
    Ah, I found the explanation. *the \ in the format shall result in a test for a parameter that is unset or null; omission of the \ shall result in a test for a parameter that is only unset.* -- from https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02 – smwikipedia Jan 14 '23 at 05:43

0 Answers0