0

I want to replace an image path inside all html files recursively in all folders.

#!/bin/bash

for image in images/*.png
do

  echo "sed -i .bak -e 's|$image|image2/$image|g' app/www/*.html"
  sed -i .bak -e 's|$image|image2/$image|g' app/www/*.html

done

The weird thing is that when I manually execute the command:

  sed -i .bak -e 's|images/add.png|image2/add.png|g' app/www/*.html

everything works fine and the path is replaces. However inside the for loop this doesn't work while the echo part echoes the same line as mentioned above.

Cyrus
  • 77,979
  • 13
  • 71
  • 125
Bas van Dijk
  • 8,857
  • 9
  • 53
  • 83

1 Answers1

2

You need to use " and not ' Otherwise the $image is not evaluated

Edit: it works in the echo because the ' surrounded string is surrounded by " ;)

Denny Weinberg
  • 2,294
  • 1
  • 18
  • 33