title: Script for adding a disk to fstab if not existing
body: <p>First of all, I have read many posts (see at bottom) with if-clauses to search in a file for a specific string and followed these posts 1to1, however I don't manage to get my script to work. I want to make an entry in <code>/etc/fstab</code> if it doesn't exist yet:</p>
  
  <pre><code>#!/bin/bash
  fstab=/etc/fstab
  
  if grep -q "poky-disc" "$fstab"
  then
      echo "#poky-disc" &gt;&gt; /etc/fstab
      echo "/dev/sdb1 /media/poky ext4 defaults 0 2" &gt;&gt; /etc/fstab
  else
      echo "Entry in fstab exists."
  fi
  </code></pre>
  
  <p>Thanks for your help in advance. These are the similar posts, which didnt help me further:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/q/4749330/5316879">How to test if string exists in file with Bash shell?</a></li>
  <li><a href="https://stackoverflow.com/q/11287861/5316879">How to check if a file contains a specific string using bash</a></li>
  </ul>