title: Trouble using if statement in bash script to check if package installed
body: <p>I am new to Bash scripting and having difficulty writing this function that I want to use to check if a package is installed or not. My code is:</p>
  <pre class="lang-sh prettyprint-override"><code>#!/bin/bash
  
  function is_installed() {
      if [ -n $(dpkg -l | awk &quot;/^ii  $1/&quot;)]; then
          echo 1;
      fi
      echo 0;
  }
  
  if is_installed &quot;coreutils&quot;; then
      echo &quot;coreutils installed&quot;;
  else
      echo &quot;coreutils not installed&quot;;
  fi
  </code></pre>
  <p>Instead of the expected behavior of printing only &quot;coreutils installed&quot;, this prints &quot;0&quot;, then &quot;1&quot;, then &quot;coreutils installed&quot; into the terminal. I think I am not understanding something about Bash syntax here, particularly with complicated if-thens. Any help?</p>