Skip to content

Instantly share code, notes, and snippets.

@jeromebodart
Forked from kongchen/setprop.sh
Created January 31, 2022 08:24
Show Gist options
  • Save jeromebodart/f1e870df3ac9ba833cdedc258af1d03c to your computer and use it in GitHub Desktop.
Save jeromebodart/f1e870df3ac9ba833cdedc258af1d03c to your computer and use it in GitHub Desktop.
set properties file value by key via bash shell
#!/bin/bash
############################
#script function
############################
setProperty(){
awk -v pat="^$1=" -v value="$1=$2" '{ if ($0 ~ pat) print value; else print $0; }' $3 > $3.tmp
mv $3.tmp $3
}
############################
### usage: setProperty $key $value $filename
setProperty "store.folder" "/opt/current/store" "env.properties"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment