“let” command is not found in my bash script
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
|
show 1 more comment
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
That's not abasherror message; you aren't running your script withbash.
– 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,$SHELLdoes 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
|
show 1 more comment
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
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
bash
edited Feb 22 '17 at 13:52
user26767
asked Feb 22 '17 at 13:41
user26767user26767
4626
4626
That's not abasherror message; you aren't running your script withbash.
– 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,$SHELLdoes 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
|
show 1 more comment
That's not abasherror message; you aren't running your script withbash.
– 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,$SHELLdoes 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
|
show 1 more comment
3 Answers
3
active
oldest
votes
do in this way:
i=$((i+1))
or
i=$(expr $i + 1)
1
If$((...))doesn't work, there's no reason to believeexpris available either.
– chepner
Feb 22 '17 at 13:51
add a comment |
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?
2
If you run the script by passing its name as an argument to a specific interpreter (likesh), 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
add a comment |
I also had the same error, checking I found that with this code you get what you need
i=`expr $i + 1`
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
do in this way:
i=$((i+1))
or
i=$(expr $i + 1)
1
If$((...))doesn't work, there's no reason to believeexpris available either.
– chepner
Feb 22 '17 at 13:51
add a comment |
do in this way:
i=$((i+1))
or
i=$(expr $i + 1)
1
If$((...))doesn't work, there's no reason to believeexpris available either.
– chepner
Feb 22 '17 at 13:51
add a comment |
do in this way:
i=$((i+1))
or
i=$(expr $i + 1)
do in this way:
i=$((i+1))
or
i=$(expr $i + 1)
answered Feb 22 '17 at 13:45
KentKent
144k25153214
144k25153214
1
If$((...))doesn't work, there's no reason to believeexpris available either.
– chepner
Feb 22 '17 at 13:51
add a comment |
1
If$((...))doesn't work, there's no reason to believeexpris 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
add a comment |
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?
2
If you run the script by passing its name as an argument to a specific interpreter (likesh), 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
add a comment |
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?
2
If you run the script by passing its name as an argument to a specific interpreter (likesh), 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
add a comment |
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?
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?
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 (likesh), 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
add a comment |
2
If you run the script by passing its name as an argument to a specific interpreter (likesh), 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
add a comment |
I also had the same error, checking I found that with this code you get what you need
i=`expr $i + 1`
add a comment |
I also had the same error, checking I found that with this code you get what you need
i=`expr $i + 1`
add a comment |
I also had the same error, checking I found that with this code you get what you need
i=`expr $i + 1`
I also had the same error, checking I found that with this code you get what you need
i=`expr $i + 1`
answered Nov 19 '18 at 23:28
jhonxitojhonxito
1
1
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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

That's not a
basherror message; you aren't running your script withbash.– 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,
$SHELLdoes 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