I have the following bash
script which repeats for each image found. It needs to iterated over all html, css and js files, and replace all occurrences of an image within that file.
for image in app/www/images-theme-dark/*.png
do
echo "installing icon" $image
# extract filename from iconpath
iconfile=$(basename $image)
iconPath="images/"$(basename $image)
# replace paths in all files containing icon paths
find app/www -type f \( -name "*.html" -or -name "*.css" -or -name "*.js" \
-or -name "*.appcache" \) \
-exec sed -i '' -e 's|$iconPath|images-theme-dark/$iconfile|g' "{}" \;
done
However when I run the script sed
gives:
sed: can't read : No such file or directory
On StackOverflow I've found sed: can't read : No such file or directory But I already had quotes around {}
When I echo the sed
command and and execute it on the command line manually there is no error.
I am using GNU sed v4.2.2 on Raspbian GNU/Linux 8.0 (jessie)
Does someone see what could be wrong here?
''
aftersed -i
? – Drawstring-i ''
by-i
. For your next problem see my first comment. – Longobard-i ''
"prevents sed to create a backup file and replaces directly in the file instead", but have your actually checked that what you think is correct? Hint: you are wrong. – Legislator-i
is one difference between GNU sed and sed from mac os. – Longobard-i
means in-place, that is, edit in the file directly.-i ''
means edit in place a file whose name is the empty string. Since probably you don't actually have a file whose name is the empty string,sed
complains that it cannot read it. – Legislator-i
, not as a separate argument. For example,sed -i.bak
will edit a file in place and make a backup by appending.bak
. A separate argument is taken as the name of a file to edit. Tested with GNUsed
4.2.2. – Legislator-e
, can be between file names. Now I think your comment should be an answer; and be voted up. – Mile