Skip to content

Instantly share code, notes, and snippets.

@marzvrover
Created December 27, 2017 20:41
Show Gist options
  • Save marzvrover/f68445c7ed5fd3694a340e6a6c1d4997 to your computer and use it in GitHub Desktop.
Save marzvrover/f68445c7ed5fd3694a340e6a6c1d4997 to your computer and use it in GitHub Desktop.
Simple script to update variables in a file. Use with variables files where the pattern is key=value.
#!/usr/bin/env bash
var_file_location="/usr/local/etc/php/php.ini"
declare -A values
values["upload_max_filesize"]="2M"
for key in "${!values[@]}"
do
grep -q "^$key" $var_file_location && \
sed -i "s/^\($key\).*/\1=$(eval echo \${values[$key]})/" $var_file_location || \
echo "$key=${values[$key]}" >> $var_file_location
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment