Created
November 19, 2018 19:58
-
-
Save w33tmaricich/c7f1c3f4b35df3dd93729898ca506358 to your computer and use it in GitHub Desktop.
bash: check before appending to file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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