“let” command is not found in my bash script












1















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.










share|improve this question

























  • That's not a bash error message; you aren't running your script with bash.

    – chepner
    Feb 22 '17 at 13:52











  • Thank you for the info, I will check and try them out.

    – user26767
    Feb 22 '17 at 13:54











  • @chepner, Yes, now I realized it works with "bash myscript.sh". Doesn't it run bash if I write "#!/bin/bash" on the top of the script?

    – user26767
    Feb 22 '17 at 13:57






  • 1





    It should; how are you running it? Incidentally, $SHELL does not contain the name of the current shell; it's the name of your default shell.

    – chepner
    Feb 22 '17 at 14:00













  • Even my default shell is /bin/bash, I checked just open a terminal and type $SHELL. I am confused.

    – user26767
    Feb 22 '17 at 14:07
















1















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.










share|improve this question

























  • That's not a bash error message; you aren't running your script with bash.

    – chepner
    Feb 22 '17 at 13:52











  • Thank you for the info, I will check and try them out.

    – user26767
    Feb 22 '17 at 13:54











  • @chepner, Yes, now I realized it works with "bash myscript.sh". Doesn't it run bash if I write "#!/bin/bash" on the top of the script?

    – user26767
    Feb 22 '17 at 13:57






  • 1





    It should; how are you running it? Incidentally, $SHELL does not contain the name of the current shell; it's the name of your default shell.

    – chepner
    Feb 22 '17 at 14:00













  • Even my default shell is /bin/bash, I checked just open a terminal and type $SHELL. I am confused.

    – user26767
    Feb 22 '17 at 14:07














1












1








1








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.










share|improve this question
















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.







bash






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 22 '17 at 13:52







user26767

















asked Feb 22 '17 at 13:41









user26767user26767

4626




4626













  • That's not a bash error message; you aren't running your script with bash.

    – chepner
    Feb 22 '17 at 13:52











  • Thank you for the info, I will check and try them out.

    – user26767
    Feb 22 '17 at 13:54











  • @chepner, Yes, now I realized it works with "bash myscript.sh". Doesn't it run bash if I write "#!/bin/bash" on the top of the script?

    – user26767
    Feb 22 '17 at 13:57






  • 1





    It should; how are you running it? Incidentally, $SHELL does not contain the name of the current shell; it's the name of your default shell.

    – chepner
    Feb 22 '17 at 14:00













  • Even my default shell is /bin/bash, I checked just open a terminal and type $SHELL. I am confused.

    – user26767
    Feb 22 '17 at 14:07



















  • That's not a bash error message; you aren't running your script with bash.

    – chepner
    Feb 22 '17 at 13:52











  • Thank you for the info, I will check and try them out.

    – user26767
    Feb 22 '17 at 13:54











  • @chepner, Yes, now I realized it works with "bash myscript.sh". Doesn't it run bash if I write "#!/bin/bash" on the top of the script?

    – user26767
    Feb 22 '17 at 13:57






  • 1





    It should; how are you running it? Incidentally, $SHELL does not contain the name of the current shell; it's the name of your default shell.

    – chepner
    Feb 22 '17 at 14:00













  • Even my default shell is /bin/bash, I checked just open a terminal and type $SHELL. I am confused.

    – user26767
    Feb 22 '17 at 14:07

















That's not a bash error message; you aren't running your script with bash.

– chepner
Feb 22 '17 at 13:52





That's not a bash error message; you aren't running your script with bash.

– chepner
Feb 22 '17 at 13:52













Thank you for the info, I will check and try them out.

– user26767
Feb 22 '17 at 13:54





Thank you for the info, I will check and try them out.

– user26767
Feb 22 '17 at 13:54













@chepner, Yes, now I realized it works with "bash myscript.sh". Doesn't it run bash if I write "#!/bin/bash" on the top of the script?

– user26767
Feb 22 '17 at 13:57





@chepner, Yes, now I realized it works with "bash myscript.sh". Doesn't it run bash if I write "#!/bin/bash" on the top of the script?

– user26767
Feb 22 '17 at 13:57




1




1





It should; how are you running it? Incidentally, $SHELL does not contain the name of the current shell; it's the name of your default shell.

– chepner
Feb 22 '17 at 14:00







It should; how are you running it? Incidentally, $SHELL does not contain the name of the current shell; it's the name of your default shell.

– chepner
Feb 22 '17 at 14:00















Even my default shell is /bin/bash, I checked just open a terminal and type $SHELL. I am confused.

– user26767
Feb 22 '17 at 14:07





Even my default shell is /bin/bash, I checked just open a terminal and type $SHELL. I am confused.

– user26767
Feb 22 '17 at 14:07












3 Answers
3






active

oldest

votes


















1














do in this way:



i=$((i+1))


or



i=$(expr $i + 1)





share|improve this answer



















  • 1





    If $((...)) doesn't work, there's no reason to believe expr is available either.

    – chepner
    Feb 22 '17 at 13:51



















0














I am sorry for answering my question.
I was running my script with sh script.sh not bash script.sh. bash script.sh worked fine.



But isn't that I can specify it by #!/bin/bash on the top of a script?






share|improve this answer



















  • 2





    If you run the script by passing its name as an argument to a specific interpreter (like sh), the shebang is ignored. It is only used when you make the script executable and run it directly (chmod +x script.sh; ./script.sh)

    – chepner
    Feb 22 '17 at 14:04








  • 1





    Thank you very much for the comment! It explained clearly and saved me a lot of time. I was stucked in this for long time.

    – user26767
    Feb 22 '17 at 14:10











  • @user26767: please accept an answer to prevent others spending time on this.

    – cdarke
    Feb 22 '17 at 15:31



















0














I also had the same error, checking I found that with this code you get what you need



i=`expr $i + 1`





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42393137%2flet-command-is-not-found-in-my-bash-script%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    do in this way:



    i=$((i+1))


    or



    i=$(expr $i + 1)





    share|improve this answer



















    • 1





      If $((...)) doesn't work, there's no reason to believe expr is available either.

      – chepner
      Feb 22 '17 at 13:51
















    1














    do in this way:



    i=$((i+1))


    or



    i=$(expr $i + 1)





    share|improve this answer



















    • 1





      If $((...)) doesn't work, there's no reason to believe expr is available either.

      – chepner
      Feb 22 '17 at 13:51














    1












    1








    1







    do in this way:



    i=$((i+1))


    or



    i=$(expr $i + 1)





    share|improve this answer













    do in this way:



    i=$((i+1))


    or



    i=$(expr $i + 1)






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Feb 22 '17 at 13:45









    KentKent

    144k25153214




    144k25153214








    • 1





      If $((...)) doesn't work, there's no reason to believe expr is available either.

      – chepner
      Feb 22 '17 at 13:51














    • 1





      If $((...)) doesn't work, there's no reason to believe expr is available either.

      – chepner
      Feb 22 '17 at 13:51








    1




    1





    If $((...)) doesn't work, there's no reason to believe expr is available either.

    – chepner
    Feb 22 '17 at 13:51





    If $((...)) doesn't work, there's no reason to believe expr is available either.

    – chepner
    Feb 22 '17 at 13:51













    0














    I am sorry for answering my question.
    I was running my script with sh script.sh not bash script.sh. bash script.sh worked fine.



    But isn't that I can specify it by #!/bin/bash on the top of a script?






    share|improve this answer



















    • 2





      If you run the script by passing its name as an argument to a specific interpreter (like sh), the shebang is ignored. It is only used when you make the script executable and run it directly (chmod +x script.sh; ./script.sh)

      – chepner
      Feb 22 '17 at 14:04








    • 1





      Thank you very much for the comment! It explained clearly and saved me a lot of time. I was stucked in this for long time.

      – user26767
      Feb 22 '17 at 14:10











    • @user26767: please accept an answer to prevent others spending time on this.

      – cdarke
      Feb 22 '17 at 15:31
















    0














    I am sorry for answering my question.
    I was running my script with sh script.sh not bash script.sh. bash script.sh worked fine.



    But isn't that I can specify it by #!/bin/bash on the top of a script?






    share|improve this answer



















    • 2





      If you run the script by passing its name as an argument to a specific interpreter (like sh), the shebang is ignored. It is only used when you make the script executable and run it directly (chmod +x script.sh; ./script.sh)

      – chepner
      Feb 22 '17 at 14:04








    • 1





      Thank you very much for the comment! It explained clearly and saved me a lot of time. I was stucked in this for long time.

      – user26767
      Feb 22 '17 at 14:10











    • @user26767: please accept an answer to prevent others spending time on this.

      – cdarke
      Feb 22 '17 at 15:31














    0












    0








    0







    I am sorry for answering my question.
    I was running my script with sh script.sh not bash script.sh. bash script.sh worked fine.



    But isn't that I can specify it by #!/bin/bash on the top of a script?






    share|improve this answer













    I am sorry for answering my question.
    I was running my script with sh script.sh not bash script.sh. bash script.sh worked fine.



    But isn't that I can specify it by #!/bin/bash on the top of a script?







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Feb 22 '17 at 14:03









    user26767user26767

    4626




    4626








    • 2





      If you run the script by passing its name as an argument to a specific interpreter (like sh), the shebang is ignored. It is only used when you make the script executable and run it directly (chmod +x script.sh; ./script.sh)

      – chepner
      Feb 22 '17 at 14:04








    • 1





      Thank you very much for the comment! It explained clearly and saved me a lot of time. I was stucked in this for long time.

      – user26767
      Feb 22 '17 at 14:10











    • @user26767: please accept an answer to prevent others spending time on this.

      – cdarke
      Feb 22 '17 at 15:31














    • 2





      If you run the script by passing its name as an argument to a specific interpreter (like sh), the shebang is ignored. It is only used when you make the script executable and run it directly (chmod +x script.sh; ./script.sh)

      – chepner
      Feb 22 '17 at 14:04








    • 1





      Thank you very much for the comment! It explained clearly and saved me a lot of time. I was stucked in this for long time.

      – user26767
      Feb 22 '17 at 14:10











    • @user26767: please accept an answer to prevent others spending time on this.

      – cdarke
      Feb 22 '17 at 15:31








    2




    2





    If you run the script by passing its name as an argument to a specific interpreter (like sh), the shebang is ignored. It is only used when you make the script executable and run it directly (chmod +x script.sh; ./script.sh)

    – chepner
    Feb 22 '17 at 14:04







    If you run the script by passing its name as an argument to a specific interpreter (like sh), the shebang is ignored. It is only used when you make the script executable and run it directly (chmod +x script.sh; ./script.sh)

    – chepner
    Feb 22 '17 at 14:04






    1




    1





    Thank you very much for the comment! It explained clearly and saved me a lot of time. I was stucked in this for long time.

    – user26767
    Feb 22 '17 at 14:10





    Thank you very much for the comment! It explained clearly and saved me a lot of time. I was stucked in this for long time.

    – user26767
    Feb 22 '17 at 14:10













    @user26767: please accept an answer to prevent others spending time on this.

    – cdarke
    Feb 22 '17 at 15:31





    @user26767: please accept an answer to prevent others spending time on this.

    – cdarke
    Feb 22 '17 at 15:31











    0














    I also had the same error, checking I found that with this code you get what you need



    i=`expr $i + 1`





    share|improve this answer




























      0














      I also had the same error, checking I found that with this code you get what you need



      i=`expr $i + 1`





      share|improve this answer


























        0












        0








        0







        I also had the same error, checking I found that with this code you get what you need



        i=`expr $i + 1`





        share|improve this answer













        I also had the same error, checking I found that with this code you get what you need



        i=`expr $i + 1`






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 23:28









        jhonxitojhonxito

        1




        1






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42393137%2flet-command-is-not-found-in-my-bash-script%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith