1# Append a line to a file, but only if the line isn't already in the file.
5# echo "This is my new line" >> myfile.txt
7# but it will only insert it once, and won't insert it repeatedly if you
8# call the function again.
10function append_to_file_if_not_exists --description "Append a line to a file, but only if it's not already there" --argument-names target_file line_to_append
11 if not grep --quiet --fixed-strings --line-regexp "$line_to_append" "$target_file" 2>/dev/null
12 echo "$line_to_append" >>"$target_file"