Following is a simple shell script to demonstrate how environment variables are accessible.if [[ ${x+X} = X ]] ## If $x is setthen  if [[ -n $x ]] ## if $x is not empty  then    printf  \$x = %s\n $x  else    printf  \$x is set but empty\n  fielse  printf  %s is not set\n \$xfiHowever, I had the following doubts with regards to the first if condition.Inside the [[ operator a single = is used for comparison.But isn't = an assignment operator ?Could you please explain ${x+X} works in this script ?
Comparison and brace expansion
bash
{   unset x    echo ${x+you won't see this}    x=    echo ${x+this you'll see} ${x:+and this you won't}    x=1    echo ${x+now you'll} ${x:+see it all}}this you'll seenow you'll see it allPractically all of the basic POSIX parameter expansions behave differently when the expanded parameter is either unset or null depending on the : optional colon modifier.The + form of parameter expansion expands to word when the parameter is set regardless of its contents in the expansion:${parameter+word}However, it does not expand to word when $parameter is set but null in the following:${parameter:+word}There are also the expansion forms for -, =, and ?. The - will expand to word when $parameter is unset, or, with :, when it is either unset or null. The = will expand identically as -, except that it will also set the null or unset $parameter's value to word. And ? kills a shell while writing an optional word error message to stderr when $parameter is unset, or, with :, of null value. For any of these three, if the $parameter is set, and, with :, is not null, then $parameter expands to its value just as it would otherwise.