I have the following bash script,
#!/bin/bash
echo $SHELL
i=1
for img in ../img/*.png; do
echo $img
new=$(printf "../img/tmp/pyr%d.png" "$i")
echo $new
# cp "$img" "$new"
let i=i+1
done
# avconv -r 2 -i ../img/tmp/pyr%d.png -b:v 1000k ../pop_pyr.mp4
In the ../img
folder, there are files pyr1920.png
, pyr1925.png
, ...
When I run this script, I get this error
../img/pyr1920.png
../img/tmp/pyr1.png
make_video.sh: 10: make_video.sh: let: not found
../img/pyr1925.png
../img/tmp/pyr1.png
But I pasted the script in a terminal, it works perfectly fine.
../img/pyr1920.png
../img/tmp/pyr1.png
../img/pyr1925.png
../img/tmp/pyr2.png
My environment it ubuntu 14.04. I understand that default /bin/sh is dash. I make sure to use bash and check by echo $SHELL
.
Why it doesn't work as a script but works fine from a terminal? I tried to find a solution but all I can find is about "dash" and "bash" setting.
do in this way:
i=$((i+1))
or
i=$(expr $i + 1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With