I am trying to modify a config file
demo.cfg
.sh
sed
read -r -p "(Default PATH: /my/default/path/): " response
case $response in
(*[![:blank:]]*) sed -i '/key_one/s/= ''.*/= '$response'/' demo.cfg; echo 'OK';;
(*) echo 'Using default path'
esac
$response
sed: -e expression #1, char 20: unknown option to "s"
demo.cfg
[params]
key_one = 1
key_two = 9
Try passing response
like this
${response//\//\\/}
This replaces all /
with \/
. Example:
$ response=/my/path/to/target
$ echo ${response//\//\\/}
\/my\/path\/to\/target
There is also an issue with your case statement. Your bash script should look like this:
#!/bin/bash
read -r -p "(Default PATH: /my/default/path/): " response
case $response in
*[![:blank:]]*) sed -i "/key_one/s/= .*/= ${response//\//\\/}/" demo.cfg
echo 'OK'
;;
*) echo 'Using default path'
;;
esac