#!/bin/bash # Given a filename, a regex pattern to match and a string: # If found, no change, else append file with string on new line. grep $2 $1 >/dev/null if [ $? -ne 0 ]; then # Not found; append on new line (silently) echo $3 | sudo tee -a $1 >/dev/null fi