0

I've a script

#!/bin/bash
mv /home/nnice/Downloads/Images/* /run/media/nnice/New\ Volume/FILES/Softwares/HTTP/Downloads/Images

mv /home/nnice/Downloads/Video/* /run/media/nnice/New\ Volume/FILES/Softwares/HTTP/Downloads/Videos

I need to replace path using sed command. I've stored paths in variables

replace="/run/media/nnice/New\ Volume/FILES/Softwares/HTTP/Downloads/"
replacewith="/home/nnice/Windows/D/FILES/Softwares/HTTP/Downloads/"

I am trying following command but it doesn't work

sed -i "s/$replace/$replacewith/g" script.sh

I've also used different separators instead of / but script remains unchanged.

[nnice@myhost scripts]$ sed  "s|$replace|$replacewith|g" script.sh
#!/bin/bash
mv /home/nnice/Downloads/Images/* /run/media/nnice/New\ Volume/FILES/Softwares/HTTP/Downloads/Images

mv /home/nnice/Downloads/Video/* /run/media/nnice/New\ Volume/FILES/Softwares/HTTP/Downloads/Videos

can you please help me with that to replace them using sed command?

Thank you

Nitin Kumar
  • 59
  • 1
  • 6

1 Answers1

1

Your command fails because you're using the same separator for the sed command and your file paths. File paths need to use / but sed separators can be anything, so try this:

sed -i "s@$replace@$replacewith@g" script.sh
John Zwinck
  • 239,568
  • 38
  • 324
  • 436