Skip to content

Instantly share code, notes, and snippets.

@w33tmaricich
Created November 19, 2018 19:58
Show Gist options
  • Save w33tmaricich/c7f1c3f4b35df3dd93729898ca506358 to your computer and use it in GitHub Desktop.
Save w33tmaricich/c7f1c3f4b35df3dd93729898ca506358 to your computer and use it in GitHub Desktop.
bash: check before appending to file
#!/bin/bash
FILE_PATH=somefile.txt
function appendToFile {
echo $@ >> $FILE_PATH
}
function checkBeforeAppend {
(cat $FILE_PATH | grep "$@" && echo "$@ already set") || appendToFile "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment