Reputation: 41
I am trying to do an automated build. There is a properties file in the format
#gpudb.conf
license_key =
I would like to write a wrapper script that I call the main script passing the license key as a command line option.
installer.sh <<license_key_value>>
I would like the installer.sh
to replace the config file
sudo -H -u gpudb bash -c "sed -i 's/\(license_key\s*=\s*\).*/\1$1/' /opt/gpudb/core/etc/gpudb.conf"
$1 seems to work with simple string. If I have a large license file with lots of characters I get the following error.
sed: -e expression #1, char 40: unknown option to `s'
Upvotes: 0
Views: 65
Reputation: 158100
Looks like the key may contain a forward slash which would break the sed command because it is using it as a delimiter. Probably you may find a delimiter that will never be part of a key and use it as the delimiter in sed? Like this:
sed 's_SEARCH_REPLACE_' # I'm _ as the delimiter
Otherwise I would recommend to use awk because it can handle fixed strings:
awk -v key="${key}" '/license_key/{print "license_key =", key;next}1' < file > file.tmp
mv file.tmp file
Upvotes: 1