Syntax error while calling a function

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











up vote
2
down vote

favorite












So I tried making a function in a script that creates a new variable for each argument when running the script. This is my code:



#!/bin/bash

# Creating function log
#ARG1=$1

log()
echo "You called DA LOG FUNCTION!!!1!!11one111!"


log

#echo "$1"
#echo "$ARG1"

fcta()
for ((x=0;x<1000;++x)); do
"a$x"=$1
if [[ $# -gt 1 ]]; then
shift
else
x=1001
fi
echo "$a$x"
# echo "$1"


fcta $@


I get this:



vagrant@localhost vagrant]$./luser-demo10.sh 12 12 12
You called DA LOG FUNCTION!!!1!!11one111!
./luser-demo10.sh: line 25: syntax error near unexpected token `}'
./luser-demo10.sh: line 25: `}'
[04:11----------------------------------------
vagrant@localhost vagrant]$


So this is line 25



# echo "$1"
} <----- LINE 25

fcta $@


EDIT: Thanks for telling me about the missing "done".
People asked what I was trying to do, well I asked another question for that, since this one has been answered (question was, why did I get a syntax error).
Thanks again.







share|improve this question


























    up vote
    2
    down vote

    favorite












    So I tried making a function in a script that creates a new variable for each argument when running the script. This is my code:



    #!/bin/bash

    # Creating function log
    #ARG1=$1

    log()
    echo "You called DA LOG FUNCTION!!!1!!11one111!"


    log

    #echo "$1"
    #echo "$ARG1"

    fcta()
    for ((x=0;x<1000;++x)); do
    "a$x"=$1
    if [[ $# -gt 1 ]]; then
    shift
    else
    x=1001
    fi
    echo "$a$x"
    # echo "$1"


    fcta $@


    I get this:



    vagrant@localhost vagrant]$./luser-demo10.sh 12 12 12
    You called DA LOG FUNCTION!!!1!!11one111!
    ./luser-demo10.sh: line 25: syntax error near unexpected token `}'
    ./luser-demo10.sh: line 25: `}'
    [04:11----------------------------------------
    vagrant@localhost vagrant]$


    So this is line 25



    # echo "$1"
    } <----- LINE 25

    fcta $@


    EDIT: Thanks for telling me about the missing "done".
    People asked what I was trying to do, well I asked another question for that, since this one has been answered (question was, why did I get a syntax error).
    Thanks again.







    share|improve this question
























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      So I tried making a function in a script that creates a new variable for each argument when running the script. This is my code:



      #!/bin/bash

      # Creating function log
      #ARG1=$1

      log()
      echo "You called DA LOG FUNCTION!!!1!!11one111!"


      log

      #echo "$1"
      #echo "$ARG1"

      fcta()
      for ((x=0;x<1000;++x)); do
      "a$x"=$1
      if [[ $# -gt 1 ]]; then
      shift
      else
      x=1001
      fi
      echo "$a$x"
      # echo "$1"


      fcta $@


      I get this:



      vagrant@localhost vagrant]$./luser-demo10.sh 12 12 12
      You called DA LOG FUNCTION!!!1!!11one111!
      ./luser-demo10.sh: line 25: syntax error near unexpected token `}'
      ./luser-demo10.sh: line 25: `}'
      [04:11----------------------------------------
      vagrant@localhost vagrant]$


      So this is line 25



      # echo "$1"
      } <----- LINE 25

      fcta $@


      EDIT: Thanks for telling me about the missing "done".
      People asked what I was trying to do, well I asked another question for that, since this one has been answered (question was, why did I get a syntax error).
      Thanks again.







      share|improve this question














      So I tried making a function in a script that creates a new variable for each argument when running the script. This is my code:



      #!/bin/bash

      # Creating function log
      #ARG1=$1

      log()
      echo "You called DA LOG FUNCTION!!!1!!11one111!"


      log

      #echo "$1"
      #echo "$ARG1"

      fcta()
      for ((x=0;x<1000;++x)); do
      "a$x"=$1
      if [[ $# -gt 1 ]]; then
      shift
      else
      x=1001
      fi
      echo "$a$x"
      # echo "$1"


      fcta $@


      I get this:



      vagrant@localhost vagrant]$./luser-demo10.sh 12 12 12
      You called DA LOG FUNCTION!!!1!!11one111!
      ./luser-demo10.sh: line 25: syntax error near unexpected token `}'
      ./luser-demo10.sh: line 25: `}'
      [04:11----------------------------------------
      vagrant@localhost vagrant]$


      So this is line 25



      # echo "$1"
      } <----- LINE 25

      fcta $@


      EDIT: Thanks for telling me about the missing "done".
      People asked what I was trying to do, well I asked another question for that, since this one has been answered (question was, why did I get a syntax error).
      Thanks again.









      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 22 at 9:10

























      asked Aug 22 at 8:21









      iamAguest

      995




      995




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote



          accepted










          In your function there is a do but no matching done to close the command list.



          Try shellcheck to verify your scripts. This is a report of detected bugs and suspicious points in your script:



          Line 16:
          for ((x=0;x<1000;++x)); do
          ^-- SC1009: The mentioned syntax error was in this for loop.
          ^-- SC1073: Couldn't parse this arithmetic for condition. Fix to allow more checks.
          ^-- SC1061: Couldn't find 'done' for this 'do'.

          Line 25:
          }
          ^-- SC1062: Expected 'done' matching previously mentioned 'do'.
          ^-- SC1072: Unexpected keyword/token. Fix any mentioned problems and try again.





          share|improve this answer





























            up vote
            3
            down vote













            andcoz showed what was wrong in your code (a missing done to close the loop, for starters), but I think it looks as if you really want an array.



            It's unclear what you want your code to do, but it looks like it's approximately equivalent of copying the command line arguments to an array:



            a=( "$@" )


            You can then get a particular element of that array with $a[i] if i is a variable with an integer value.



            It's important to double quote the expansion of $@ as this would quote the individual elements of the $@ list. Without the double quotes, the elements would be split on whitespaces (the contents of IFS), and filename generation ("globbing") would be performed on them.




            Another comment about your code: Use break to exit a loop instead of setting the loop variable to a value past the end of the loop.






            share|improve this answer






















              Your Answer







              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "106"
              ;
              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',
              convertImagesToLinks: false,
              noModals: false,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );








               

              draft saved


              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f464071%2fsyntax-error-while-calling-a-function%23new-answer', 'question_page');

              );

              Post as a guest






























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              4
              down vote



              accepted










              In your function there is a do but no matching done to close the command list.



              Try shellcheck to verify your scripts. This is a report of detected bugs and suspicious points in your script:



              Line 16:
              for ((x=0;x<1000;++x)); do
              ^-- SC1009: The mentioned syntax error was in this for loop.
              ^-- SC1073: Couldn't parse this arithmetic for condition. Fix to allow more checks.
              ^-- SC1061: Couldn't find 'done' for this 'do'.

              Line 25:
              }
              ^-- SC1062: Expected 'done' matching previously mentioned 'do'.
              ^-- SC1072: Unexpected keyword/token. Fix any mentioned problems and try again.





              share|improve this answer


























                up vote
                4
                down vote



                accepted










                In your function there is a do but no matching done to close the command list.



                Try shellcheck to verify your scripts. This is a report of detected bugs and suspicious points in your script:



                Line 16:
                for ((x=0;x<1000;++x)); do
                ^-- SC1009: The mentioned syntax error was in this for loop.
                ^-- SC1073: Couldn't parse this arithmetic for condition. Fix to allow more checks.
                ^-- SC1061: Couldn't find 'done' for this 'do'.

                Line 25:
                }
                ^-- SC1062: Expected 'done' matching previously mentioned 'do'.
                ^-- SC1072: Unexpected keyword/token. Fix any mentioned problems and try again.





                share|improve this answer
























                  up vote
                  4
                  down vote



                  accepted







                  up vote
                  4
                  down vote



                  accepted






                  In your function there is a do but no matching done to close the command list.



                  Try shellcheck to verify your scripts. This is a report of detected bugs and suspicious points in your script:



                  Line 16:
                  for ((x=0;x<1000;++x)); do
                  ^-- SC1009: The mentioned syntax error was in this for loop.
                  ^-- SC1073: Couldn't parse this arithmetic for condition. Fix to allow more checks.
                  ^-- SC1061: Couldn't find 'done' for this 'do'.

                  Line 25:
                  }
                  ^-- SC1062: Expected 'done' matching previously mentioned 'do'.
                  ^-- SC1072: Unexpected keyword/token. Fix any mentioned problems and try again.





                  share|improve this answer














                  In your function there is a do but no matching done to close the command list.



                  Try shellcheck to verify your scripts. This is a report of detected bugs and suspicious points in your script:



                  Line 16:
                  for ((x=0;x<1000;++x)); do
                  ^-- SC1009: The mentioned syntax error was in this for loop.
                  ^-- SC1073: Couldn't parse this arithmetic for condition. Fix to allow more checks.
                  ^-- SC1061: Couldn't find 'done' for this 'do'.

                  Line 25:
                  }
                  ^-- SC1062: Expected 'done' matching previously mentioned 'do'.
                  ^-- SC1072: Unexpected keyword/token. Fix any mentioned problems and try again.






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Aug 22 at 8:53

























                  answered Aug 22 at 8:47









                  andcoz

                  11.8k32938




                  11.8k32938






















                      up vote
                      3
                      down vote













                      andcoz showed what was wrong in your code (a missing done to close the loop, for starters), but I think it looks as if you really want an array.



                      It's unclear what you want your code to do, but it looks like it's approximately equivalent of copying the command line arguments to an array:



                      a=( "$@" )


                      You can then get a particular element of that array with $a[i] if i is a variable with an integer value.



                      It's important to double quote the expansion of $@ as this would quote the individual elements of the $@ list. Without the double quotes, the elements would be split on whitespaces (the contents of IFS), and filename generation ("globbing") would be performed on them.




                      Another comment about your code: Use break to exit a loop instead of setting the loop variable to a value past the end of the loop.






                      share|improve this answer


























                        up vote
                        3
                        down vote













                        andcoz showed what was wrong in your code (a missing done to close the loop, for starters), but I think it looks as if you really want an array.



                        It's unclear what you want your code to do, but it looks like it's approximately equivalent of copying the command line arguments to an array:



                        a=( "$@" )


                        You can then get a particular element of that array with $a[i] if i is a variable with an integer value.



                        It's important to double quote the expansion of $@ as this would quote the individual elements of the $@ list. Without the double quotes, the elements would be split on whitespaces (the contents of IFS), and filename generation ("globbing") would be performed on them.




                        Another comment about your code: Use break to exit a loop instead of setting the loop variable to a value past the end of the loop.






                        share|improve this answer
























                          up vote
                          3
                          down vote










                          up vote
                          3
                          down vote









                          andcoz showed what was wrong in your code (a missing done to close the loop, for starters), but I think it looks as if you really want an array.



                          It's unclear what you want your code to do, but it looks like it's approximately equivalent of copying the command line arguments to an array:



                          a=( "$@" )


                          You can then get a particular element of that array with $a[i] if i is a variable with an integer value.



                          It's important to double quote the expansion of $@ as this would quote the individual elements of the $@ list. Without the double quotes, the elements would be split on whitespaces (the contents of IFS), and filename generation ("globbing") would be performed on them.




                          Another comment about your code: Use break to exit a loop instead of setting the loop variable to a value past the end of the loop.






                          share|improve this answer














                          andcoz showed what was wrong in your code (a missing done to close the loop, for starters), but I think it looks as if you really want an array.



                          It's unclear what you want your code to do, but it looks like it's approximately equivalent of copying the command line arguments to an array:



                          a=( "$@" )


                          You can then get a particular element of that array with $a[i] if i is a variable with an integer value.



                          It's important to double quote the expansion of $@ as this would quote the individual elements of the $@ list. Without the double quotes, the elements would be split on whitespaces (the contents of IFS), and filename generation ("globbing") would be performed on them.




                          Another comment about your code: Use break to exit a loop instead of setting the loop variable to a value past the end of the loop.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Aug 22 at 9:33

























                          answered Aug 22 at 9:06









                          Kusalananda

                          104k14206324




                          104k14206324






















                               

                              draft saved


                              draft discarded


























                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f464071%2fsyntax-error-while-calling-a-function%23new-answer', 'question_page');

                              );

                              Post as a guest













































































                              這個網誌中的熱門文章

                              How to combine Bézier curves to a surface?

                              Mutual Information Always Non-negative

                              Why am i infinitely getting the same tweet with the Twitter Search API?