title: Parse postgres result in bash
body: <p>By running this line of code: </p>
  
  <pre><code>psql -c "\l" -p 54049
  </code></pre>
  
  <p>I am getting the below result:</p>
  
  <p><a href="https://i.stack.imgur.com/eAtz1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eAtz1.png" alt="enter image description here"></a></p>
  
  <p>my questions are a bit general BASH</p>
  
  <p>1- how can I parse a table like this in BASH</p>
  
  <p>2- what are this type of tables called</p>
  
  <p>3- any hands on training tutorials for learning BASH in the hard way</p>
  
  <p>4- and how can I parse this table as arrays of an array so that each row will be as an array and each its elements to be as the columns?</p>
  
  <p><strong>Main question :</strong> 
  I want to compare my manual input with this table therefore if my input db name exists in the result it will continue else it will else again.</p>
  
  <p>Here is the code which is not working: </p>
  
  <pre><code>dbsList=`psql -c "\l" -p 54049 | awk '{ print $1 }'`
  
  echo "Please enter a valid DB name you want to backup:"
  read dbName
  
  contains() {
      [[ $1 =~ (^|[[:space:]])"$2"($|[[:space:]]) ]] &amp;&amp; echo 0 || echo 1
  }
  
  contains dbsList dbName
  
  while [ `contains dbsList dbName` -eq 1 ]
  do
  echo "Please enter a valid DB name you want to backup:"
  read dbName
  done
  </code></pre>