#!/bin/bash
for i in $(ls /home/bob/images)
do
if [[ $i =~ *.jpeg ]]
then
n=$(echo $i| sed ‘s/jpeg/jpg/g’)
mv /home/bob/images/$i /home/bob/images/$n
# mv – $i “$i.html”
f
#!/bin/bash
for i in $(ls /home/bob/images)
do
if [[ $i =~ *.jpeg ]]
then
n=$(echo $i| sed ‘s/jpeg/jpg/g’)
mv /home/bob/images/$i /home/bob/images/$n
# mv – $i “$i.html”
f
It looks like there are a few issues with the script you provided. For instance, you’re using =~
for pattern matching, which is mostly used with grep
, and the pattern should be quoted, which you haven’t. Additionally, I noticed that the if
conditional block is missing its closing statement, and there’s no done
to signify the end of the for
loop.
If you could share the link to the lab you are working on, I would be better able to suggest a fix or provide you with an updated script.
Regards.
It is called “regex pattern matching” (not to be confused with “shell pattern matching”). And in most cases it should NOT be quoted, because the quoted part would treated as a fixed string, and not as a regex pattern.
But yes, the script in overall is lacking the correct syntax, and uses some really “bad practices”, which should be avoided (always validate your code with e.g. https://www.shellcheck.net website).