Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"let" command is not found in my bash script

Tags:

bash

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.

like image 631
user26767 Avatar asked Dec 11 '22 12:12

user26767


1 Answers

do in this way:

i=$((i+1))

or

i=$(expr $i + 1)
like image 50
Kent Avatar answered Dec 28 '22 22:12

Kent