I am trying to make a copy of all .txt files in a folder but renamed so that they are .html files.
for f in my-txt-folder/*.txt
a="$(echo $f | sed s/.txt/.html/)"
cp "$f" "$a"
my.html-folder/file.txt: No such file or directory.
Match on end of line, e.g.
for f in my-txt-folder/*.txt do a="$(echo $f | sed -e 's/\.txt$/.html/')" cp "$f" "$a" done
Previously the "." you have matched with
sed was a wildcard character, and you didn't anchor the pattern at end-of-line.
There is another solution all in bash from heemayl which was just posted; the advantage of an all-shell solution is that you don't have to learn the fine points of
sed just yet.