-
-
Save addlistener/6d74e8fd6d35117e952c5044f7f63ef2 to your computer and use it in GitHub Desktop.
ubuntu add or change config file entry
This file contains hidden or 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
function add_or_change { | |
TARGET_KEY=$1 | |
REPLACEMENT_VALUE=$2 | |
CONFIG_FILE=$3 | |
if grep -e "^\s*$TARGET_KEY\s*=" "$CONFIG_FILE"; then | |
sed -i 's/^\('"$TARGET_KEY"'\s*=\s*\).*$/\1'"$REPLACEMENT_VALUE"'/' $CONFIG_FILE | |
grep -e "^\s*$TARGET_KEY\s*=" "$CONFIG_FILE" | |
else | |
echo "$TARGET_KEY=$REPLACEMENT_VALUE" >> "$CONFIG_FILE" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment