Reputation: 43
I am trying to loop inside a directory and rename the file name with space. But i m getting the bad substitution error while running it with sh test.sh
#!/bin/bash
for f in /home/admin1/abc/*.kmz
do
mv "$f" "${f// /_}"
#rm $i
done
Since i need to configure in crontab i may need to run it with sh command not with ./
Upvotes: 0
Views: 12093
Reputation: 169051
To make my comment an answer:
You're running with sh
, but your script declares it's a bash
script. On many systems sh
is not bash
, but a lighter shell that doesn't support all bashisms.
Either
bash test.sh
, orchmod u+x
and run ./test.sh
to use the shebang line.Upvotes: 5
Reputation: 3361
Bourne Shell sh
doesn't support this type of substitution. You could run this script:
for f in /home/admin1/abc/*.kmz
do
mv "$f" `echo "$f" |tr ' ' _`
done
Upvotes: 1