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
  • 84,225
  • 14
  • 89
  • 153
Bas van Dijk
  • 9,933
  • 10
  • 55
  • 91

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,492
  • 1
  • 21
  • 34