1 # Update the variable $var in $rcfile: The function update_$VAR must
2 # exist. It is called with the old value of $var, and must return the
5 update_rcfile_setting() {
8 # The characters $, `, ", and \ have special meaning inside double
9 # quoted shell variables. The characters " and \ have special meaning
10 # inside awk double-quoted variables.
12 local old=$(source "$rcfile" ;
14 | sed -e 's/\([$`"\\]\)/\\\1/g')
15 local new=$(eval update_$var "$old" \
16 | sed -e 's/\([$`"\\]\)/\\\1/g' \
17 -e 's/\(["\\]\)/\\\1/g')
18 local tmp=$(mktemp /tmp/${rcfile##/*}.XXXXXX)
20 # This script breaks for multi-line varables -- I don't think
21 # we need to handle this special case.
25 print "'"$var"'=\"'"$new"'\""
29 /^'"$var"'=/ { replace() ; next }