How can I make a bash counter script work when executing it from another script? [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0
















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?










share|improve this question















marked as duplicate by Kusalananda bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

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 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











  • 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















0
















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?










share|improve this question















marked as duplicate by Kusalananda bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

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 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











  • 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













0












0








0









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?










share|improve this question

















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

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 bash
Users with the  bash badge can single-handedly close bash questions as duplicates and reopen them as needed.

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 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











  • 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











  • 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










2 Answers
2






active

oldest

votes


















1














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.






share|improve this answer






























    1














    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.






    share|improve this answer































      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      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.






      share|improve this answer



























        1














        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.






        share|improve this answer

























          1












          1








          1







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 22 at 3:22









          CrypteyaCrypteya

          19313




          19313























              1














              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.






              share|improve this answer





























                1














                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.






                share|improve this answer



























                  1












                  1








                  1







                  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.






                  share|improve this answer















                  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.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 22 at 18:54

























                  answered Jan 21 at 23:47









                  user1133275user1133275

                  3,274723




                  3,274723












                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Displaying single band from multi-band raster using QGIS

                      How many registers does an x86_64 CPU actually have?