title: How can I use a secret variable in Azure Devops bash task which could be undefined
body: <p>I am trying to create a config file using a bash task in Azure Devops. The variables come from azure keyvault, so I don't know which variables are defined and which ones are undefined.</p>
  <pre class="lang-yaml prettyprint-override"><code>- script: |
      touch config.txt
      echo &quot;1. $(MyDefinedVariable)&quot; &gt;&gt; config.txt
      echo &quot;2. $(MyUndefinedVariable)&quot; &gt;&gt; config.txt
      cat config.txt
  </code></pre>
  <p>Since <code>MyUndefinedVariable</code> is not defined, the pipeline doesn't substitute <code>$(MyUndefinedVariable)</code>, resulting in a bash error <code>MyUndefinedVariable: command not found</code>.</p>
  <p>I have tried using the <code>env</code> argument to use bash variables but I get the same error since &quot;$(MyUndefinedVariable)&quot; is being passed in to the bash environment.</p>
  <pre class="lang-yaml prettyprint-override"><code>- script: |
      touch config.txt
      echo &quot;1. $MY_DEFINED_VARIABLE&quot; &gt;&gt; config.txt
      echo &quot;2. $MY_UNDEFINED_VARIABLE&quot; &gt;&gt; config.txt
      cat config.txt
    env:
      MY_DEFINED_VARIABLE: $(MyDefinedVariable)
      MY_UNDEFINED_VARIABLE: $(MyUndefinedVariable)
  </code></pre>
  <p>I just want undefined variables to resolve to an empty string but can't find a sensible way to do it.</p>