title: how to have conditional part in gdbinit based on the environnment
body: <p>In the <a href="https://sourceware.org/gdb/current/onlinedocs/gdb/Command-Files.html#Command-Files" rel="nofollow noreferrer">gdb manual</a> there is this part:</p>
  
  <blockquote>
    <p><strong>if else</strong></p>
    
    <p>This command allows to include in your script conditionally
    executed commands. The if command takes a single argument, which is an
    expression to evaluate...</p>
  </blockquote>
  
  <p>I can perform tests in my gdbinit when I use a numeric expression, like</p>
  
  <pre><code>if (42 == 42)
      print "42"
  end
  </code></pre>
  
  <p>But when I want to perform a test on a String, like this:</p>
  
  <pre><code>if ("a" == "a")
      print "yes"
  end
  </code></pre>
  
  <p>then I got an error when I start gdb:</p>
  
  <pre><code>.gdbinit:45: Error in sourced command file:
  You can't do that without a process to debug.
  </code></pre>
  
  <p>I tried, unsuccessfully, to find documentation or examples for the expression syntax in order to write my conditional block.</p>
  
  <p>What I want to achieve is to add a bunch of command based on an environment variable. So I need to have this kind of section in my gdbinit:</p>
  
  <pre><code>if ("${myEnvVar}" == "someSpecialValue")
      #my set of special values
  end
  </code></pre>
  
  <p>How to achieve that ? </p>
  
  <p>edit: looks like the easiest way is to use python to perform this kind of operation: <a href="https://stackoverflow.com/questions/9814185/how-to-access-environment-variables-inside-gdbinit-and-inside-gdb-itself">How to access environment variables inside .gdbinit and inside gdb itself?</a></p>
  
  <p>If there's no way to achieve this with 'pure' gdb commands, I guess that this question should be closed as a duplicate.</p>