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 /etc/fstab
if it doesn't exist yet:
#!/bin/bash
fstab=/etc/fstab
if grep -q "poky-disc" "$fstab"
then
echo "#poky-disc" >> /etc/fstab
echo "/dev/sdb1 /media/poky ext4 defaults 0 2" >> /etc/fstab
else
echo "Entry in fstab exists."
fi
Thanks for your help in advance. These are the similar posts, which didnt help me further: