-1

I need to replace a literal variable value in a file, I'm trying to use SED but it doesn't seem to be working. Below is the command I'm using, but when I check the file the value hasn't changed.

sed -i .bak "s|isJBossRunning \\\${home}|isJBossRunning \\\${home_dir}|g" /file/location/file.sh

Here is an example of what I'm trying to do. In my file.sh file.

home='/opt/tmp'

home_dir='/usr/share/jbossas'

JBOSS_USER=jbossas

SERVER_NAME=abxd

echo isJBossRunning ${JBOSS_USER} ${home} ${SERVER_NAME}

So what I want to do is replace the string isJBossRunning ${JBOSS_USER} ${home} ${SERVER_NAME} so I replace the ${home} with ${home_dir}.

jww
  • 97,681
  • 90
  • 411
  • 885
JBerto
  • 143
  • 5
  • 16
  • 1
    What value are you trying to replace and by what? – choroba Jun 15 '18 at 20:22
  • Please let us know the values of $home, and $home_dir, and the contents of file.sh – Leonard Jun 15 '18 at 20:27
  • I'm not trying to replace the value of those variables, I just want to replace the text within the file so that "isJBossRunning ${home}" is replaced with "isJBossRunning ${home_dir}. – JBerto Jun 15 '18 at 20:34
  • [What characters do I need to escape when using sed in a sh script?](https://unix.stackexchange.com/q/32907/56041), [Escape a string for a sed replace pattern](https://stackoverflow.com/q/407523/608639), [How to pass a variable containing slashes to sed](https://stackoverflow.com/q/27787536/608639), [Is there a way to prevent sed from interpreting the replacement string?](https://unix.stackexchange.com/q/255789/56041), etc. – jww Jun 16 '18 at 01:45

1 Answers1

0

I figured out a way of updating the file. Below is the command I used, I just replaced the literal variable in the entire file.

sed -i "s/\${home}/\${home_dir}/" ./file.sh
JBerto
  • 143
  • 5
  • 16