How can I make a bash counter script work when executing it from another script? [duplicate]
Clash Royale CLAN TAG#URR8PPP
This question already has an answer here:
Which shell interpreter runs a script with no shebang?
3 answers
I have a script that uses wget and saves the output to a file with a name of an incrementing variable.
Counter.sh:
number=1
for i in $(cat file)
do
wget $i -S -O $number.html 2>&1
((number++))
sleep 1
echo 'done'
done
I can run the script from the command line and it operates perfectly.
However when I execute it from within another script:
Script 2:
./counter.sh
I receive the following output:
scripts/counter.sh: 5: scripts/counter.sh: number++: not found
done
scripts/counter.sh: 5: scripts/counter.sh: number++: not found
done
scripts/counter.sh: 5: scripts/counter.sh: number++: not found
done
scripts/counter.sh: 5: scripts/counter.sh: number++: not found
done
For some reason the counter ++ is not working when executed from within another script. How can I fix this?
bash shell-script
marked as duplicate by Kusalananda
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jan 22 at 19:38
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Which shell interpreter runs a script with no shebang?
3 answers
I have a script that uses wget and saves the output to a file with a name of an incrementing variable.
Counter.sh:
number=1
for i in $(cat file)
do
wget $i -S -O $number.html 2>&1
((number++))
sleep 1
echo 'done'
done
I can run the script from the command line and it operates perfectly.
However when I execute it from within another script:
Script 2:
./counter.sh
I receive the following output:
scripts/counter.sh: 5: scripts/counter.sh: number++: not found
done
scripts/counter.sh: 5: scripts/counter.sh: number++: not found
done
scripts/counter.sh: 5: scripts/counter.sh: number++: not found
done
scripts/counter.sh: 5: scripts/counter.sh: number++: not found
done
For some reason the counter ++ is not working when executed from within another script. How can I fix this?
bash shell-script
marked as duplicate by Kusalananda
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jan 22 at 19:38
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
We cannot see the shebang lines at the beginning of your scripts, since you included just parts of them, so I'm just guessing. You may incur in that error if your script is invoked in a shell that does not support that syntax (((number++))
), e.g. if your default shell isdash
.
– fra-san
Jan 21 at 22:00
Try adding#!/bin/bash
as the first line of your script.
– Crypteya
Jan 21 at 22:09
This worked! thanks, i'm not sure why this happend though as /bin/bash is my default shell
– jonny b
Jan 21 at 22:11
add a comment |
This question already has an answer here:
Which shell interpreter runs a script with no shebang?
3 answers
I have a script that uses wget and saves the output to a file with a name of an incrementing variable.
Counter.sh:
number=1
for i in $(cat file)
do
wget $i -S -O $number.html 2>&1
((number++))
sleep 1
echo 'done'
done
I can run the script from the command line and it operates perfectly.
However when I execute it from within another script:
Script 2:
./counter.sh
I receive the following output:
scripts/counter.sh: 5: scripts/counter.sh: number++: not found
done
scripts/counter.sh: 5: scripts/counter.sh: number++: not found
done
scripts/counter.sh: 5: scripts/counter.sh: number++: not found
done
scripts/counter.sh: 5: scripts/counter.sh: number++: not found
done
For some reason the counter ++ is not working when executed from within another script. How can I fix this?
bash shell-script
This question already has an answer here:
Which shell interpreter runs a script with no shebang?
3 answers
I have a script that uses wget and saves the output to a file with a name of an incrementing variable.
Counter.sh:
number=1
for i in $(cat file)
do
wget $i -S -O $number.html 2>&1
((number++))
sleep 1
echo 'done'
done
I can run the script from the command line and it operates perfectly.
However when I execute it from within another script:
Script 2:
./counter.sh
I receive the following output:
scripts/counter.sh: 5: scripts/counter.sh: number++: not found
done
scripts/counter.sh: 5: scripts/counter.sh: number++: not found
done
scripts/counter.sh: 5: scripts/counter.sh: number++: not found
done
scripts/counter.sh: 5: scripts/counter.sh: number++: not found
done
For some reason the counter ++ is not working when executed from within another script. How can I fix this?
This question already has an answer here:
Which shell interpreter runs a script with no shebang?
3 answers
bash shell-script
bash shell-script
edited Jan 21 at 23:56
fra-san
1,5461416
1,5461416
asked Jan 21 at 21:43
jonny bjonny b
336
336
marked as duplicate by Kusalananda
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jan 22 at 19:38
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Kusalananda
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Jan 22 at 19:38
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
We cannot see the shebang lines at the beginning of your scripts, since you included just parts of them, so I'm just guessing. You may incur in that error if your script is invoked in a shell that does not support that syntax (((number++))
), e.g. if your default shell isdash
.
– fra-san
Jan 21 at 22:00
Try adding#!/bin/bash
as the first line of your script.
– Crypteya
Jan 21 at 22:09
This worked! thanks, i'm not sure why this happend though as /bin/bash is my default shell
– jonny b
Jan 21 at 22:11
add a comment |
We cannot see the shebang lines at the beginning of your scripts, since you included just parts of them, so I'm just guessing. You may incur in that error if your script is invoked in a shell that does not support that syntax (((number++))
), e.g. if your default shell isdash
.
– fra-san
Jan 21 at 22:00
Try adding#!/bin/bash
as the first line of your script.
– Crypteya
Jan 21 at 22:09
This worked! thanks, i'm not sure why this happend though as /bin/bash is my default shell
– jonny b
Jan 21 at 22:11
We cannot see the shebang lines at the beginning of your scripts, since you included just parts of them, so I'm just guessing. You may incur in that error if your script is invoked in a shell that does not support that syntax (
((number++))
), e.g. if your default shell is dash
.– fra-san
Jan 21 at 22:00
We cannot see the shebang lines at the beginning of your scripts, since you included just parts of them, so I'm just guessing. You may incur in that error if your script is invoked in a shell that does not support that syntax (
((number++))
), e.g. if your default shell is dash
.– fra-san
Jan 21 at 22:00
Try adding
#!/bin/bash
as the first line of your script.– Crypteya
Jan 21 at 22:09
Try adding
#!/bin/bash
as the first line of your script.– Crypteya
Jan 21 at 22:09
This worked! thanks, i'm not sure why this happend though as /bin/bash is my default shell
– jonny b
Jan 21 at 22:11
This worked! thanks, i'm not sure why this happend though as /bin/bash is my default shell
– jonny b
Jan 21 at 22:11
add a comment |
2 Answers
2
active
oldest
votes
it looks like your shell is trying to operate on the variable number++
rather than applying an arithmetic operation to the variable number
. This is likely because the ++
syntax is not supported in your shell.
To get around this you can specify the shell that you would like the script to execute with. To do this, add
#!/bin/bash
as the first line of your script.
add a comment |
Use
#!/bin/bash
or
bash counter.sh
or make it compatible with
#!/bin/sh
Generally one should use an IDE or paste your code into https://www.shellcheck.net to avoid issues like that.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
it looks like your shell is trying to operate on the variable number++
rather than applying an arithmetic operation to the variable number
. This is likely because the ++
syntax is not supported in your shell.
To get around this you can specify the shell that you would like the script to execute with. To do this, add
#!/bin/bash
as the first line of your script.
add a comment |
it looks like your shell is trying to operate on the variable number++
rather than applying an arithmetic operation to the variable number
. This is likely because the ++
syntax is not supported in your shell.
To get around this you can specify the shell that you would like the script to execute with. To do this, add
#!/bin/bash
as the first line of your script.
add a comment |
it looks like your shell is trying to operate on the variable number++
rather than applying an arithmetic operation to the variable number
. This is likely because the ++
syntax is not supported in your shell.
To get around this you can specify the shell that you would like the script to execute with. To do this, add
#!/bin/bash
as the first line of your script.
it looks like your shell is trying to operate on the variable number++
rather than applying an arithmetic operation to the variable number
. This is likely because the ++
syntax is not supported in your shell.
To get around this you can specify the shell that you would like the script to execute with. To do this, add
#!/bin/bash
as the first line of your script.
answered Jan 22 at 3:22
CrypteyaCrypteya
19313
19313
add a comment |
add a comment |
Use
#!/bin/bash
or
bash counter.sh
or make it compatible with
#!/bin/sh
Generally one should use an IDE or paste your code into https://www.shellcheck.net to avoid issues like that.
add a comment |
Use
#!/bin/bash
or
bash counter.sh
or make it compatible with
#!/bin/sh
Generally one should use an IDE or paste your code into https://www.shellcheck.net to avoid issues like that.
add a comment |
Use
#!/bin/bash
or
bash counter.sh
or make it compatible with
#!/bin/sh
Generally one should use an IDE or paste your code into https://www.shellcheck.net to avoid issues like that.
Use
#!/bin/bash
or
bash counter.sh
or make it compatible with
#!/bin/sh
Generally one should use an IDE or paste your code into https://www.shellcheck.net to avoid issues like that.
edited Jan 22 at 18:54
answered Jan 21 at 23:47
user1133275user1133275
3,274723
3,274723
add a comment |
add a comment |
We cannot see the shebang lines at the beginning of your scripts, since you included just parts of them, so I'm just guessing. You may incur in that error if your script is invoked in a shell that does not support that syntax (
((number++))
), e.g. if your default shell isdash
.– fra-san
Jan 21 at 22:00
Try adding
#!/bin/bash
as the first line of your script.– Crypteya
Jan 21 at 22:09
This worked! thanks, i'm not sure why this happend though as /bin/bash is my default shell
– jonny b
Jan 21 at 22:11