title: What does an if statement with only a variable evaluate to in bash?
body: <p>I'm learning about bash --login and saw that the commands in <code>/etc/profile</code> are executed first. In that file:</p>
  
  <pre><code># /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
  # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
  
  if [ "`id -u`" -eq 0 ]; then
    PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
  else
    PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
  fi
  export PATH
  
  if [ "$PS1" ]; then
    if [ "$BASH" ] &amp;&amp; [ "$BASH" != "/bin/sh" ]; then
      # The file bash.bashrc already sets the default PS1.
      # PS1='\h:\w\$ '
      if [ -f /etc/bash.bashrc ]; then
        . /etc/bash.bashrc
      fi
    else
      if [ "`id -u`" -eq 0 ]; then
        PS1='# '
      else
        PS1='$ '
      fi
    fi
  fi
  
  if [ -d /etc/profile.d ]; then
    for i in /etc/profile.d/*.sh; do
      if [ -r $i ]; then
        . $i
      fi
    done
    unset i
  fi
  </code></pre>
  
  <p>Now, I admittedly have a limited understanding of control flow in bash but from my understanding, most of the time what I see put in the if statement is some kind of conditional statement, whether it is <code>[-a FILENAME]</code> to check if a file exists or a comparison between strings, usually it evaluates to something. </p>
  
  <p><strong>In the file, two if statements confuse me:</strong></p>
  
  <p><code>if [ "$PS1" ];</code> and <code>if[ "$BASH" ]</code></p>
  
  <p>I know that PS1 is a variable for the primary prompt, but that's all that's in the if statement. It's not using -a to check existence or comparing it to something else. My educated guess is that simply putting a variable will evaluate to true if it exists.</p>
  
  <p>My question is <em>what do these if statements evaluate to and why?</em></p>