Created
December 1, 2017 19:30
-
-
Save jaytaylor/42a09cdc6297cef9a7aca42ab734a95d to your computer and use it in GitHub Desktop.
Bash function to set or append to a Java settings 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
function set_or_append_java_config() { | |
local FILE=$1 | |
local KEY=$2 | |
local VALUE=$3 | |
if grep -q "^${KEY}=" "${FILE}"; then | |
sed -i -e "s#^\\(${KEY}=\\).*"'$'"#\\1${VALUE}#" "${FILE}" | |
else | |
echo "${KEY}=${VALUE}" >> "${FILE}" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on the solution here: https://stackoverflow.com/questions/13456564/append-or-modify-keys-in-conf-files-using-sed-bash-one-liner