shell script error : Syntax error: “(” unexpected

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











up vote
0
down vote

favorite












I have checked the previous post on this error. still did not get the solution working. Here is my bash script. can some one help me figure out the issue . I have used https://www.shellcheck.net/ to see any error. I did not find any.



Error:



Dockerfunctiontest.sh: 2: Dockerfunctiontest.sh: Syntax error: "(" unexpected


script:



#!/bin/bash
function BuildSimpleContainer ()

docker search mariadb
docker pull mariadb:latest
docker run --name mariadbtestfour -e MYSQL_ROOT_PASSWORD=mypass -d mariadb --log-bin --binlog-format=MIXED
docker exec -it mariadbtest bash
apt-get -qq update
apt-get -qq -y install curl
apt-get -qq -y install wget
apt-get update
apt-get install apt-transport-https
apt-get update
cd /home
mkdir mdsd
cd mdsd/
wget '<blob url to pfx file>'
echo "certififcate Downloaded"
wget '<blob url file1>'
echo "file1 Downloaded"
wget 'blob url file2'
echo "file2 Downloaded"

BuildSimpleContainer






share|improve this question






















  • The error message is pretty self-explanatory: the ( shouldn't be there on line 2.
    – devius
    Feb 26 at 19:31







  • 2




    How do you call this script?
    – Tomasz
    Feb 26 at 19:34






  • 1




    @tomasz has hit it right on the nose. The script is being executed by sh, not bash, and is choking on the function declaration syntax.
    – DopeGhoti
    Feb 26 at 19:38










  • Related: difference between "function foo() " and "foo() "
    – Stéphane Chazelas
    Feb 26 at 20:53














up vote
0
down vote

favorite












I have checked the previous post on this error. still did not get the solution working. Here is my bash script. can some one help me figure out the issue . I have used https://www.shellcheck.net/ to see any error. I did not find any.



Error:



Dockerfunctiontest.sh: 2: Dockerfunctiontest.sh: Syntax error: "(" unexpected


script:



#!/bin/bash
function BuildSimpleContainer ()

docker search mariadb
docker pull mariadb:latest
docker run --name mariadbtestfour -e MYSQL_ROOT_PASSWORD=mypass -d mariadb --log-bin --binlog-format=MIXED
docker exec -it mariadbtest bash
apt-get -qq update
apt-get -qq -y install curl
apt-get -qq -y install wget
apt-get update
apt-get install apt-transport-https
apt-get update
cd /home
mkdir mdsd
cd mdsd/
wget '<blob url to pfx file>'
echo "certififcate Downloaded"
wget '<blob url file1>'
echo "file1 Downloaded"
wget 'blob url file2'
echo "file2 Downloaded"

BuildSimpleContainer






share|improve this question






















  • The error message is pretty self-explanatory: the ( shouldn't be there on line 2.
    – devius
    Feb 26 at 19:31







  • 2




    How do you call this script?
    – Tomasz
    Feb 26 at 19:34






  • 1




    @tomasz has hit it right on the nose. The script is being executed by sh, not bash, and is choking on the function declaration syntax.
    – DopeGhoti
    Feb 26 at 19:38










  • Related: difference between "function foo() " and "foo() "
    – Stéphane Chazelas
    Feb 26 at 20:53












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have checked the previous post on this error. still did not get the solution working. Here is my bash script. can some one help me figure out the issue . I have used https://www.shellcheck.net/ to see any error. I did not find any.



Error:



Dockerfunctiontest.sh: 2: Dockerfunctiontest.sh: Syntax error: "(" unexpected


script:



#!/bin/bash
function BuildSimpleContainer ()

docker search mariadb
docker pull mariadb:latest
docker run --name mariadbtestfour -e MYSQL_ROOT_PASSWORD=mypass -d mariadb --log-bin --binlog-format=MIXED
docker exec -it mariadbtest bash
apt-get -qq update
apt-get -qq -y install curl
apt-get -qq -y install wget
apt-get update
apt-get install apt-transport-https
apt-get update
cd /home
mkdir mdsd
cd mdsd/
wget '<blob url to pfx file>'
echo "certififcate Downloaded"
wget '<blob url file1>'
echo "file1 Downloaded"
wget 'blob url file2'
echo "file2 Downloaded"

BuildSimpleContainer






share|improve this question














I have checked the previous post on this error. still did not get the solution working. Here is my bash script. can some one help me figure out the issue . I have used https://www.shellcheck.net/ to see any error. I did not find any.



Error:



Dockerfunctiontest.sh: 2: Dockerfunctiontest.sh: Syntax error: "(" unexpected


script:



#!/bin/bash
function BuildSimpleContainer ()

docker search mariadb
docker pull mariadb:latest
docker run --name mariadbtestfour -e MYSQL_ROOT_PASSWORD=mypass -d mariadb --log-bin --binlog-format=MIXED
docker exec -it mariadbtest bash
apt-get -qq update
apt-get -qq -y install curl
apt-get -qq -y install wget
apt-get update
apt-get install apt-transport-https
apt-get update
cd /home
mkdir mdsd
cd mdsd/
wget '<blob url to pfx file>'
echo "certififcate Downloaded"
wget '<blob url file1>'
echo "file1 Downloaded"
wget 'blob url file2'
echo "file2 Downloaded"

BuildSimpleContainer








share|improve this question













share|improve this question




share|improve this question








edited Feb 26 at 20:21









Tomasz

8,04052560




8,04052560










asked Feb 26 at 19:24









Bobby

122




122











  • The error message is pretty self-explanatory: the ( shouldn't be there on line 2.
    – devius
    Feb 26 at 19:31







  • 2




    How do you call this script?
    – Tomasz
    Feb 26 at 19:34






  • 1




    @tomasz has hit it right on the nose. The script is being executed by sh, not bash, and is choking on the function declaration syntax.
    – DopeGhoti
    Feb 26 at 19:38










  • Related: difference between "function foo() " and "foo() "
    – Stéphane Chazelas
    Feb 26 at 20:53
















  • The error message is pretty self-explanatory: the ( shouldn't be there on line 2.
    – devius
    Feb 26 at 19:31







  • 2




    How do you call this script?
    – Tomasz
    Feb 26 at 19:34






  • 1




    @tomasz has hit it right on the nose. The script is being executed by sh, not bash, and is choking on the function declaration syntax.
    – DopeGhoti
    Feb 26 at 19:38










  • Related: difference between "function foo() " and "foo() "
    – Stéphane Chazelas
    Feb 26 at 20:53















The error message is pretty self-explanatory: the ( shouldn't be there on line 2.
– devius
Feb 26 at 19:31





The error message is pretty self-explanatory: the ( shouldn't be there on line 2.
– devius
Feb 26 at 19:31





2




2




How do you call this script?
– Tomasz
Feb 26 at 19:34




How do you call this script?
– Tomasz
Feb 26 at 19:34




1




1




@tomasz has hit it right on the nose. The script is being executed by sh, not bash, and is choking on the function declaration syntax.
– DopeGhoti
Feb 26 at 19:38




@tomasz has hit it right on the nose. The script is being executed by sh, not bash, and is choking on the function declaration syntax.
– DopeGhoti
Feb 26 at 19:38












Related: difference between "function foo() " and "foo() "
– Stéphane Chazelas
Feb 26 at 20:53




Related: difference between "function foo() " and "foo() "
– Stéphane Chazelas
Feb 26 at 20:53










1 Answer
1






active

oldest

votes

















up vote
4
down vote













My guess is that you don't run this script as a Bash script, but with some other shell, which doesn't accept this syntax. Eg. sh.



As you can see in Shellcheck, and as Bash's man on my Debian confirms, this syntax is correct:



name () compound-command [redirection]
function name [()] compound-command [redirection]


You are using the second one from the two above, and your compound-command is the contents of the ... braces. And that's fine as far as man bash goes. But then, there are voices against this construct, as in the link in John Moon's comment below the other answer. And in the link to Greg's Wiki in that answer again.



Going back to your question, taking into consideration the name of the script, namely Dockerfunctiontest.sh, I might think you don't see much difference between sh and bash. Probably you run the script with this command:



sh Dockerfunctiontest.sh


While it would be reasonable to run it with either:



bash Dockerfunctiontest.sh


or



./Dockerfunctiontest.sh


The last one picks the interpreter basing on the first line in the script, namely:



#!/bin/bash


And while the interpreter named in the script is Bash, why not name the file the proper way?



Dockerfunctiontest.bash


Less confusion in the future.






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%2f426778%2fshell-script-error-syntax-error-unexpected%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote













    My guess is that you don't run this script as a Bash script, but with some other shell, which doesn't accept this syntax. Eg. sh.



    As you can see in Shellcheck, and as Bash's man on my Debian confirms, this syntax is correct:



    name () compound-command [redirection]
    function name [()] compound-command [redirection]


    You are using the second one from the two above, and your compound-command is the contents of the ... braces. And that's fine as far as man bash goes. But then, there are voices against this construct, as in the link in John Moon's comment below the other answer. And in the link to Greg's Wiki in that answer again.



    Going back to your question, taking into consideration the name of the script, namely Dockerfunctiontest.sh, I might think you don't see much difference between sh and bash. Probably you run the script with this command:



    sh Dockerfunctiontest.sh


    While it would be reasonable to run it with either:



    bash Dockerfunctiontest.sh


    or



    ./Dockerfunctiontest.sh


    The last one picks the interpreter basing on the first line in the script, namely:



    #!/bin/bash


    And while the interpreter named in the script is Bash, why not name the file the proper way?



    Dockerfunctiontest.bash


    Less confusion in the future.






    share|improve this answer
























      up vote
      4
      down vote













      My guess is that you don't run this script as a Bash script, but with some other shell, which doesn't accept this syntax. Eg. sh.



      As you can see in Shellcheck, and as Bash's man on my Debian confirms, this syntax is correct:



      name () compound-command [redirection]
      function name [()] compound-command [redirection]


      You are using the second one from the two above, and your compound-command is the contents of the ... braces. And that's fine as far as man bash goes. But then, there are voices against this construct, as in the link in John Moon's comment below the other answer. And in the link to Greg's Wiki in that answer again.



      Going back to your question, taking into consideration the name of the script, namely Dockerfunctiontest.sh, I might think you don't see much difference between sh and bash. Probably you run the script with this command:



      sh Dockerfunctiontest.sh


      While it would be reasonable to run it with either:



      bash Dockerfunctiontest.sh


      or



      ./Dockerfunctiontest.sh


      The last one picks the interpreter basing on the first line in the script, namely:



      #!/bin/bash


      And while the interpreter named in the script is Bash, why not name the file the proper way?



      Dockerfunctiontest.bash


      Less confusion in the future.






      share|improve this answer






















        up vote
        4
        down vote










        up vote
        4
        down vote









        My guess is that you don't run this script as a Bash script, but with some other shell, which doesn't accept this syntax. Eg. sh.



        As you can see in Shellcheck, and as Bash's man on my Debian confirms, this syntax is correct:



        name () compound-command [redirection]
        function name [()] compound-command [redirection]


        You are using the second one from the two above, and your compound-command is the contents of the ... braces. And that's fine as far as man bash goes. But then, there are voices against this construct, as in the link in John Moon's comment below the other answer. And in the link to Greg's Wiki in that answer again.



        Going back to your question, taking into consideration the name of the script, namely Dockerfunctiontest.sh, I might think you don't see much difference between sh and bash. Probably you run the script with this command:



        sh Dockerfunctiontest.sh


        While it would be reasonable to run it with either:



        bash Dockerfunctiontest.sh


        or



        ./Dockerfunctiontest.sh


        The last one picks the interpreter basing on the first line in the script, namely:



        #!/bin/bash


        And while the interpreter named in the script is Bash, why not name the file the proper way?



        Dockerfunctiontest.bash


        Less confusion in the future.






        share|improve this answer












        My guess is that you don't run this script as a Bash script, but with some other shell, which doesn't accept this syntax. Eg. sh.



        As you can see in Shellcheck, and as Bash's man on my Debian confirms, this syntax is correct:



        name () compound-command [redirection]
        function name [()] compound-command [redirection]


        You are using the second one from the two above, and your compound-command is the contents of the ... braces. And that's fine as far as man bash goes. But then, there are voices against this construct, as in the link in John Moon's comment below the other answer. And in the link to Greg's Wiki in that answer again.



        Going back to your question, taking into consideration the name of the script, namely Dockerfunctiontest.sh, I might think you don't see much difference between sh and bash. Probably you run the script with this command:



        sh Dockerfunctiontest.sh


        While it would be reasonable to run it with either:



        bash Dockerfunctiontest.sh


        or



        ./Dockerfunctiontest.sh


        The last one picks the interpreter basing on the first line in the script, namely:



        #!/bin/bash


        And while the interpreter named in the script is Bash, why not name the file the proper way?



        Dockerfunctiontest.bash


        Less confusion in the future.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 26 at 20:13









        Tomasz

        8,04052560




        8,04052560






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f426778%2fshell-script-error-syntax-error-unexpected%23new-answer', 'question_page');

            );

            Post as a guest













































































            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?