Shell script fails: Syntax error: “(” unexpected

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











up vote
53
down vote

favorite
9












I've been working on a script that automates setting up a development environment for Raspberry Pi development (step by step details that work are here). The script is linked in that article but convenience you can find it here also. Now when run this script install and sets up the environment without error but you have to enter your sudo password more than once due to sudo's time-out value by default. So I started experimenting by removing all the sudo lines and running the whole script via sudo at the command line like so:



kemra102@ubuntuvm:~$ sudo ./pi_dev_env_install.sh


This works fine as expected and gets most of the way through until this point:



./pi_dev_env_install: 68: ./pi_dev_env_install.sh: Syntax error: "(" unexpected


Now this line worked fine previously when not running the whole script with sudo. There is nothing about this line running as sudo that should stop it working to my knowledge, does anyone have any ideas?










share|improve this question



















  • 1




    The shebang is really in line 9? Due to Ubuntu's DashAsBinSh affinity I suspect your script is interpreted by dash instead of bash. Try to move the shebang in line 1.
    – manatwork
    Aug 18 '12 at 11:45










  • According to that article calling /bin/bash directly instead of /bin/sh will; correctly use bash instead of dash so that should not be an issue as I understand it. I can still move the shebang of course, but that doesn't really explain as to why it works when you don’t sudo the whole script.
    – kemra102
    Aug 18 '12 at 11:50










  • In my case everything was fine but as a habit, I was running my shell script with "sh" not with "bash".
    – Indrajeet Gour
    Oct 11 at 8:53














up vote
53
down vote

favorite
9












I've been working on a script that automates setting up a development environment for Raspberry Pi development (step by step details that work are here). The script is linked in that article but convenience you can find it here also. Now when run this script install and sets up the environment without error but you have to enter your sudo password more than once due to sudo's time-out value by default. So I started experimenting by removing all the sudo lines and running the whole script via sudo at the command line like so:



kemra102@ubuntuvm:~$ sudo ./pi_dev_env_install.sh


This works fine as expected and gets most of the way through until this point:



./pi_dev_env_install: 68: ./pi_dev_env_install.sh: Syntax error: "(" unexpected


Now this line worked fine previously when not running the whole script with sudo. There is nothing about this line running as sudo that should stop it working to my knowledge, does anyone have any ideas?










share|improve this question



















  • 1




    The shebang is really in line 9? Due to Ubuntu's DashAsBinSh affinity I suspect your script is interpreted by dash instead of bash. Try to move the shebang in line 1.
    – manatwork
    Aug 18 '12 at 11:45










  • According to that article calling /bin/bash directly instead of /bin/sh will; correctly use bash instead of dash so that should not be an issue as I understand it. I can still move the shebang of course, but that doesn't really explain as to why it works when you don’t sudo the whole script.
    – kemra102
    Aug 18 '12 at 11:50










  • In my case everything was fine but as a habit, I was running my shell script with "sh" not with "bash".
    – Indrajeet Gour
    Oct 11 at 8:53












up vote
53
down vote

favorite
9









up vote
53
down vote

favorite
9






9





I've been working on a script that automates setting up a development environment for Raspberry Pi development (step by step details that work are here). The script is linked in that article but convenience you can find it here also. Now when run this script install and sets up the environment without error but you have to enter your sudo password more than once due to sudo's time-out value by default. So I started experimenting by removing all the sudo lines and running the whole script via sudo at the command line like so:



kemra102@ubuntuvm:~$ sudo ./pi_dev_env_install.sh


This works fine as expected and gets most of the way through until this point:



./pi_dev_env_install: 68: ./pi_dev_env_install.sh: Syntax error: "(" unexpected


Now this line worked fine previously when not running the whole script with sudo. There is nothing about this line running as sudo that should stop it working to my knowledge, does anyone have any ideas?










share|improve this question















I've been working on a script that automates setting up a development environment for Raspberry Pi development (step by step details that work are here). The script is linked in that article but convenience you can find it here also. Now when run this script install and sets up the environment without error but you have to enter your sudo password more than once due to sudo's time-out value by default. So I started experimenting by removing all the sudo lines and running the whole script via sudo at the command line like so:



kemra102@ubuntuvm:~$ sudo ./pi_dev_env_install.sh


This works fine as expected and gets most of the way through until this point:



./pi_dev_env_install: 68: ./pi_dev_env_install.sh: Syntax error: "(" unexpected


Now this line worked fine previously when not running the whole script with sudo. There is nothing about this line running as sudo that should stop it working to my knowledge, does anyone have any ideas?







bash shell ubuntu shell-script






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 18 '12 at 12:08









Gilles

522k12610401575




522k12610401575










asked Aug 18 '12 at 11:37









kemra102

1081616




1081616







  • 1




    The shebang is really in line 9? Due to Ubuntu's DashAsBinSh affinity I suspect your script is interpreted by dash instead of bash. Try to move the shebang in line 1.
    – manatwork
    Aug 18 '12 at 11:45










  • According to that article calling /bin/bash directly instead of /bin/sh will; correctly use bash instead of dash so that should not be an issue as I understand it. I can still move the shebang of course, but that doesn't really explain as to why it works when you don’t sudo the whole script.
    – kemra102
    Aug 18 '12 at 11:50










  • In my case everything was fine but as a habit, I was running my shell script with "sh" not with "bash".
    – Indrajeet Gour
    Oct 11 at 8:53












  • 1




    The shebang is really in line 9? Due to Ubuntu's DashAsBinSh affinity I suspect your script is interpreted by dash instead of bash. Try to move the shebang in line 1.
    – manatwork
    Aug 18 '12 at 11:45










  • According to that article calling /bin/bash directly instead of /bin/sh will; correctly use bash instead of dash so that should not be an issue as I understand it. I can still move the shebang of course, but that doesn't really explain as to why it works when you don’t sudo the whole script.
    – kemra102
    Aug 18 '12 at 11:50










  • In my case everything was fine but as a habit, I was running my shell script with "sh" not with "bash".
    – Indrajeet Gour
    Oct 11 at 8:53







1




1




The shebang is really in line 9? Due to Ubuntu's DashAsBinSh affinity I suspect your script is interpreted by dash instead of bash. Try to move the shebang in line 1.
– manatwork
Aug 18 '12 at 11:45




The shebang is really in line 9? Due to Ubuntu's DashAsBinSh affinity I suspect your script is interpreted by dash instead of bash. Try to move the shebang in line 1.
– manatwork
Aug 18 '12 at 11:45












According to that article calling /bin/bash directly instead of /bin/sh will; correctly use bash instead of dash so that should not be an issue as I understand it. I can still move the shebang of course, but that doesn't really explain as to why it works when you don’t sudo the whole script.
– kemra102
Aug 18 '12 at 11:50




According to that article calling /bin/bash directly instead of /bin/sh will; correctly use bash instead of dash so that should not be an issue as I understand it. I can still move the shebang of course, but that doesn't really explain as to why it works when you don’t sudo the whole script.
– kemra102
Aug 18 '12 at 11:50












In my case everything was fine but as a habit, I was running my shell script with "sh" not with "bash".
– Indrajeet Gour
Oct 11 at 8:53




In my case everything was fine but as a habit, I was running my shell script with "sh" not with "bash".
– Indrajeet Gour
Oct 11 at 8:53










6 Answers
6






active

oldest

votes

















up vote
73
down vote



accepted










The script does not begin with a shebang line, so the system executes it with /bin/sh. On Ubuntu, /bin/sh is dash, a shell designed for fast startup and execution with only standard features. When dash reaches line 68, it sees a syntax error: that parenthesis doesn't mean anything to it in context.



Since dash (like all other shells) is an interpreter, it won't complain until the execution reaches the problematic line. So even if the script successfully started at some point in your testing, it would have aborted once line 68 was reached.



The shebang line must be the very first thing in the file. Since you use bash features, the first line of the file must be #!/bin/bash or #!/usr/bin/env bash.






share|improve this answer


















  • 2




    Thanks clearly a gap in my knowledge, I don't script much so wasn't aware of that! Thanks for the explanation it's helped a lot and will be very useful to know in the future too.
    – kemra102
    Aug 18 '12 at 12:25










  • Let me add that this error occurs even while using scripts extension for nautilus. Adding the shebang line solved it immediately. +1.
    – Bhavin Doshi
    Oct 9 '13 at 5:14










  • Facing the issue running sonarqube.sh on Ubuntu 15.10. Changed the header as said. Executing sudo sh ./sonar.sh console. Still getting the error.
    – soufrk
    Sep 1 '16 at 6:58










  • @soufrk Is it sonarqube.sh or sonar.sh? Make up your mind. And anyway, if you can't solve the problem with the information in this thread, ask a new question with the full content of the script and copy-paste the full error message(s).
    – Gilles
    Sep 1 '16 at 7:06










  • My bad !! Was running wrong arch executable. But interestingly, on the correct arch the file beginning with #! /bin/sh executed perfectly. Now, that leaves me puzzled.
    – soufrk
    Sep 1 '16 at 7:07

















up vote
5
down vote













If the shebang is not on the first line, it will not be respected, regardless of the shell of the root user, the SHELL variable or the -s flag. You can easily confirm this is with a simple example:



#
#!/bin/bash
offfset=(`ls`)
echo $offset


Running this script with sudo will raise a syntax error in recent versions of Ubuntu and Debian.



You have two options to make sure the script is interpreted by bash:



  1. Move the shebang to the first line



  2. Run sudo like this:



    sudo bash ./pi_dev_env_install.sh






share|improve this answer



























    up vote
    0
    down vote













    Maybe you have a "(" on the dir or file name.






    share|improve this answer
















    • 2




      The missing shebang was already accepted as the answer by the original poster.
      – Philipp Claßen
      Jan 22 '13 at 22:58

















    up vote
    0
    down vote













    Try dos2unix in script file. Sometimes some hidden characters are there in the source.



    command:



    dos2unix script_file.sh script_file.sh





    share|improve this answer





























      up vote
      -1
      down vote













      sudo chmod 755 <script>


      In my case the error was lack of permissions to execute the file. Only got the error message when I separated the commands:



      $ sudo sh
      # ./install


      hope it helps






      share|improve this answer




















      • Lack of permissions would not cause this error message.
        – Gilles
        Nov 27 '15 at 22:43

















      up vote
      -1
      down vote













      For me starting script with:



      bash ./< script file > 


      works fine.






      share|improve this answer






















      • That may well be true for you, but it isn't really a solution to the stated problem.
        – bu5hman
        Dec 24 '17 at 15:41










      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: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      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
      );



      );













       

      draft saved


      draft discarded


















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

      );

      Post as a guest















      Required, but never shown

























      6 Answers
      6






      active

      oldest

      votes








      6 Answers
      6






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      73
      down vote



      accepted










      The script does not begin with a shebang line, so the system executes it with /bin/sh. On Ubuntu, /bin/sh is dash, a shell designed for fast startup and execution with only standard features. When dash reaches line 68, it sees a syntax error: that parenthesis doesn't mean anything to it in context.



      Since dash (like all other shells) is an interpreter, it won't complain until the execution reaches the problematic line. So even if the script successfully started at some point in your testing, it would have aborted once line 68 was reached.



      The shebang line must be the very first thing in the file. Since you use bash features, the first line of the file must be #!/bin/bash or #!/usr/bin/env bash.






      share|improve this answer


















      • 2




        Thanks clearly a gap in my knowledge, I don't script much so wasn't aware of that! Thanks for the explanation it's helped a lot and will be very useful to know in the future too.
        – kemra102
        Aug 18 '12 at 12:25










      • Let me add that this error occurs even while using scripts extension for nautilus. Adding the shebang line solved it immediately. +1.
        – Bhavin Doshi
        Oct 9 '13 at 5:14










      • Facing the issue running sonarqube.sh on Ubuntu 15.10. Changed the header as said. Executing sudo sh ./sonar.sh console. Still getting the error.
        – soufrk
        Sep 1 '16 at 6:58










      • @soufrk Is it sonarqube.sh or sonar.sh? Make up your mind. And anyway, if you can't solve the problem with the information in this thread, ask a new question with the full content of the script and copy-paste the full error message(s).
        – Gilles
        Sep 1 '16 at 7:06










      • My bad !! Was running wrong arch executable. But interestingly, on the correct arch the file beginning with #! /bin/sh executed perfectly. Now, that leaves me puzzled.
        – soufrk
        Sep 1 '16 at 7:07














      up vote
      73
      down vote



      accepted










      The script does not begin with a shebang line, so the system executes it with /bin/sh. On Ubuntu, /bin/sh is dash, a shell designed for fast startup and execution with only standard features. When dash reaches line 68, it sees a syntax error: that parenthesis doesn't mean anything to it in context.



      Since dash (like all other shells) is an interpreter, it won't complain until the execution reaches the problematic line. So even if the script successfully started at some point in your testing, it would have aborted once line 68 was reached.



      The shebang line must be the very first thing in the file. Since you use bash features, the first line of the file must be #!/bin/bash or #!/usr/bin/env bash.






      share|improve this answer


















      • 2




        Thanks clearly a gap in my knowledge, I don't script much so wasn't aware of that! Thanks for the explanation it's helped a lot and will be very useful to know in the future too.
        – kemra102
        Aug 18 '12 at 12:25










      • Let me add that this error occurs even while using scripts extension for nautilus. Adding the shebang line solved it immediately. +1.
        – Bhavin Doshi
        Oct 9 '13 at 5:14










      • Facing the issue running sonarqube.sh on Ubuntu 15.10. Changed the header as said. Executing sudo sh ./sonar.sh console. Still getting the error.
        – soufrk
        Sep 1 '16 at 6:58










      • @soufrk Is it sonarqube.sh or sonar.sh? Make up your mind. And anyway, if you can't solve the problem with the information in this thread, ask a new question with the full content of the script and copy-paste the full error message(s).
        – Gilles
        Sep 1 '16 at 7:06










      • My bad !! Was running wrong arch executable. But interestingly, on the correct arch the file beginning with #! /bin/sh executed perfectly. Now, that leaves me puzzled.
        – soufrk
        Sep 1 '16 at 7:07












      up vote
      73
      down vote



      accepted







      up vote
      73
      down vote



      accepted






      The script does not begin with a shebang line, so the system executes it with /bin/sh. On Ubuntu, /bin/sh is dash, a shell designed for fast startup and execution with only standard features. When dash reaches line 68, it sees a syntax error: that parenthesis doesn't mean anything to it in context.



      Since dash (like all other shells) is an interpreter, it won't complain until the execution reaches the problematic line. So even if the script successfully started at some point in your testing, it would have aborted once line 68 was reached.



      The shebang line must be the very first thing in the file. Since you use bash features, the first line of the file must be #!/bin/bash or #!/usr/bin/env bash.






      share|improve this answer














      The script does not begin with a shebang line, so the system executes it with /bin/sh. On Ubuntu, /bin/sh is dash, a shell designed for fast startup and execution with only standard features. When dash reaches line 68, it sees a syntax error: that parenthesis doesn't mean anything to it in context.



      Since dash (like all other shells) is an interpreter, it won't complain until the execution reaches the problematic line. So even if the script successfully started at some point in your testing, it would have aborted once line 68 was reached.



      The shebang line must be the very first thing in the file. Since you use bash features, the first line of the file must be #!/bin/bash or #!/usr/bin/env bash.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Dec 24 '17 at 11:13









      Stéphane Chazelas

      295k54556898




      295k54556898










      answered Aug 18 '12 at 12:08









      Gilles

      522k12610401575




      522k12610401575







      • 2




        Thanks clearly a gap in my knowledge, I don't script much so wasn't aware of that! Thanks for the explanation it's helped a lot and will be very useful to know in the future too.
        – kemra102
        Aug 18 '12 at 12:25










      • Let me add that this error occurs even while using scripts extension for nautilus. Adding the shebang line solved it immediately. +1.
        – Bhavin Doshi
        Oct 9 '13 at 5:14










      • Facing the issue running sonarqube.sh on Ubuntu 15.10. Changed the header as said. Executing sudo sh ./sonar.sh console. Still getting the error.
        – soufrk
        Sep 1 '16 at 6:58










      • @soufrk Is it sonarqube.sh or sonar.sh? Make up your mind. And anyway, if you can't solve the problem with the information in this thread, ask a new question with the full content of the script and copy-paste the full error message(s).
        – Gilles
        Sep 1 '16 at 7:06










      • My bad !! Was running wrong arch executable. But interestingly, on the correct arch the file beginning with #! /bin/sh executed perfectly. Now, that leaves me puzzled.
        – soufrk
        Sep 1 '16 at 7:07












      • 2




        Thanks clearly a gap in my knowledge, I don't script much so wasn't aware of that! Thanks for the explanation it's helped a lot and will be very useful to know in the future too.
        – kemra102
        Aug 18 '12 at 12:25










      • Let me add that this error occurs even while using scripts extension for nautilus. Adding the shebang line solved it immediately. +1.
        – Bhavin Doshi
        Oct 9 '13 at 5:14










      • Facing the issue running sonarqube.sh on Ubuntu 15.10. Changed the header as said. Executing sudo sh ./sonar.sh console. Still getting the error.
        – soufrk
        Sep 1 '16 at 6:58










      • @soufrk Is it sonarqube.sh or sonar.sh? Make up your mind. And anyway, if you can't solve the problem with the information in this thread, ask a new question with the full content of the script and copy-paste the full error message(s).
        – Gilles
        Sep 1 '16 at 7:06










      • My bad !! Was running wrong arch executable. But interestingly, on the correct arch the file beginning with #! /bin/sh executed perfectly. Now, that leaves me puzzled.
        – soufrk
        Sep 1 '16 at 7:07







      2




      2




      Thanks clearly a gap in my knowledge, I don't script much so wasn't aware of that! Thanks for the explanation it's helped a lot and will be very useful to know in the future too.
      – kemra102
      Aug 18 '12 at 12:25




      Thanks clearly a gap in my knowledge, I don't script much so wasn't aware of that! Thanks for the explanation it's helped a lot and will be very useful to know in the future too.
      – kemra102
      Aug 18 '12 at 12:25












      Let me add that this error occurs even while using scripts extension for nautilus. Adding the shebang line solved it immediately. +1.
      – Bhavin Doshi
      Oct 9 '13 at 5:14




      Let me add that this error occurs even while using scripts extension for nautilus. Adding the shebang line solved it immediately. +1.
      – Bhavin Doshi
      Oct 9 '13 at 5:14












      Facing the issue running sonarqube.sh on Ubuntu 15.10. Changed the header as said. Executing sudo sh ./sonar.sh console. Still getting the error.
      – soufrk
      Sep 1 '16 at 6:58




      Facing the issue running sonarqube.sh on Ubuntu 15.10. Changed the header as said. Executing sudo sh ./sonar.sh console. Still getting the error.
      – soufrk
      Sep 1 '16 at 6:58












      @soufrk Is it sonarqube.sh or sonar.sh? Make up your mind. And anyway, if you can't solve the problem with the information in this thread, ask a new question with the full content of the script and copy-paste the full error message(s).
      – Gilles
      Sep 1 '16 at 7:06




      @soufrk Is it sonarqube.sh or sonar.sh? Make up your mind. And anyway, if you can't solve the problem with the information in this thread, ask a new question with the full content of the script and copy-paste the full error message(s).
      – Gilles
      Sep 1 '16 at 7:06












      My bad !! Was running wrong arch executable. But interestingly, on the correct arch the file beginning with #! /bin/sh executed perfectly. Now, that leaves me puzzled.
      – soufrk
      Sep 1 '16 at 7:07




      My bad !! Was running wrong arch executable. But interestingly, on the correct arch the file beginning with #! /bin/sh executed perfectly. Now, that leaves me puzzled.
      – soufrk
      Sep 1 '16 at 7:07












      up vote
      5
      down vote













      If the shebang is not on the first line, it will not be respected, regardless of the shell of the root user, the SHELL variable or the -s flag. You can easily confirm this is with a simple example:



      #
      #!/bin/bash
      offfset=(`ls`)
      echo $offset


      Running this script with sudo will raise a syntax error in recent versions of Ubuntu and Debian.



      You have two options to make sure the script is interpreted by bash:



      1. Move the shebang to the first line



      2. Run sudo like this:



        sudo bash ./pi_dev_env_install.sh






      share|improve this answer
























        up vote
        5
        down vote













        If the shebang is not on the first line, it will not be respected, regardless of the shell of the root user, the SHELL variable or the -s flag. You can easily confirm this is with a simple example:



        #
        #!/bin/bash
        offfset=(`ls`)
        echo $offset


        Running this script with sudo will raise a syntax error in recent versions of Ubuntu and Debian.



        You have two options to make sure the script is interpreted by bash:



        1. Move the shebang to the first line



        2. Run sudo like this:



          sudo bash ./pi_dev_env_install.sh






        share|improve this answer






















          up vote
          5
          down vote










          up vote
          5
          down vote









          If the shebang is not on the first line, it will not be respected, regardless of the shell of the root user, the SHELL variable or the -s flag. You can easily confirm this is with a simple example:



          #
          #!/bin/bash
          offfset=(`ls`)
          echo $offset


          Running this script with sudo will raise a syntax error in recent versions of Ubuntu and Debian.



          You have two options to make sure the script is interpreted by bash:



          1. Move the shebang to the first line



          2. Run sudo like this:



            sudo bash ./pi_dev_env_install.sh






          share|improve this answer












          If the shebang is not on the first line, it will not be respected, regardless of the shell of the root user, the SHELL variable or the -s flag. You can easily confirm this is with a simple example:



          #
          #!/bin/bash
          offfset=(`ls`)
          echo $offset


          Running this script with sudo will raise a syntax error in recent versions of Ubuntu and Debian.



          You have two options to make sure the script is interpreted by bash:



          1. Move the shebang to the first line



          2. Run sudo like this:



            sudo bash ./pi_dev_env_install.sh







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 18 '12 at 12:11









          janos

          7,06322247




          7,06322247




















              up vote
              0
              down vote













              Maybe you have a "(" on the dir or file name.






              share|improve this answer
















              • 2




                The missing shebang was already accepted as the answer by the original poster.
                – Philipp Claßen
                Jan 22 '13 at 22:58














              up vote
              0
              down vote













              Maybe you have a "(" on the dir or file name.






              share|improve this answer
















              • 2




                The missing shebang was already accepted as the answer by the original poster.
                – Philipp Claßen
                Jan 22 '13 at 22:58












              up vote
              0
              down vote










              up vote
              0
              down vote









              Maybe you have a "(" on the dir or file name.






              share|improve this answer












              Maybe you have a "(" on the dir or file name.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Jan 22 '13 at 22:34









              mauro

              11




              11







              • 2




                The missing shebang was already accepted as the answer by the original poster.
                – Philipp Claßen
                Jan 22 '13 at 22:58












              • 2




                The missing shebang was already accepted as the answer by the original poster.
                – Philipp Claßen
                Jan 22 '13 at 22:58







              2




              2




              The missing shebang was already accepted as the answer by the original poster.
              – Philipp Claßen
              Jan 22 '13 at 22:58




              The missing shebang was already accepted as the answer by the original poster.
              – Philipp Claßen
              Jan 22 '13 at 22:58










              up vote
              0
              down vote













              Try dos2unix in script file. Sometimes some hidden characters are there in the source.



              command:



              dos2unix script_file.sh script_file.sh





              share|improve this answer


























                up vote
                0
                down vote













                Try dos2unix in script file. Sometimes some hidden characters are there in the source.



                command:



                dos2unix script_file.sh script_file.sh





                share|improve this answer
























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Try dos2unix in script file. Sometimes some hidden characters are there in the source.



                  command:



                  dos2unix script_file.sh script_file.sh





                  share|improve this answer














                  Try dos2unix in script file. Sometimes some hidden characters are there in the source.



                  command:



                  dos2unix script_file.sh script_file.sh






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Apr 24 '15 at 5:31









                  muru

                  35.2k581155




                  35.2k581155










                  answered Apr 24 '15 at 5:26









                  M Sarfraz

                  1




                  1




















                      up vote
                      -1
                      down vote













                      sudo chmod 755 <script>


                      In my case the error was lack of permissions to execute the file. Only got the error message when I separated the commands:



                      $ sudo sh
                      # ./install


                      hope it helps






                      share|improve this answer




















                      • Lack of permissions would not cause this error message.
                        – Gilles
                        Nov 27 '15 at 22:43














                      up vote
                      -1
                      down vote













                      sudo chmod 755 <script>


                      In my case the error was lack of permissions to execute the file. Only got the error message when I separated the commands:



                      $ sudo sh
                      # ./install


                      hope it helps






                      share|improve this answer




















                      • Lack of permissions would not cause this error message.
                        – Gilles
                        Nov 27 '15 at 22:43












                      up vote
                      -1
                      down vote










                      up vote
                      -1
                      down vote









                      sudo chmod 755 <script>


                      In my case the error was lack of permissions to execute the file. Only got the error message when I separated the commands:



                      $ sudo sh
                      # ./install


                      hope it helps






                      share|improve this answer












                      sudo chmod 755 <script>


                      In my case the error was lack of permissions to execute the file. Only got the error message when I separated the commands:



                      $ sudo sh
                      # ./install


                      hope it helps







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 27 '15 at 22:00









                      user145114

                      1




                      1











                      • Lack of permissions would not cause this error message.
                        – Gilles
                        Nov 27 '15 at 22:43
















                      • Lack of permissions would not cause this error message.
                        – Gilles
                        Nov 27 '15 at 22:43















                      Lack of permissions would not cause this error message.
                      – Gilles
                      Nov 27 '15 at 22:43




                      Lack of permissions would not cause this error message.
                      – Gilles
                      Nov 27 '15 at 22:43










                      up vote
                      -1
                      down vote













                      For me starting script with:



                      bash ./< script file > 


                      works fine.






                      share|improve this answer






















                      • That may well be true for you, but it isn't really a solution to the stated problem.
                        – bu5hman
                        Dec 24 '17 at 15:41














                      up vote
                      -1
                      down vote













                      For me starting script with:



                      bash ./< script file > 


                      works fine.






                      share|improve this answer






















                      • That may well be true for you, but it isn't really a solution to the stated problem.
                        – bu5hman
                        Dec 24 '17 at 15:41












                      up vote
                      -1
                      down vote










                      up vote
                      -1
                      down vote









                      For me starting script with:



                      bash ./< script file > 


                      works fine.






                      share|improve this answer














                      For me starting script with:



                      bash ./< script file > 


                      works fine.







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Dec 24 '17 at 12:01









                      Jesse_b

                      11.4k23063




                      11.4k23063










                      answered Dec 24 '17 at 11:00









                      my.coolmac

                      1




                      1











                      • That may well be true for you, but it isn't really a solution to the stated problem.
                        – bu5hman
                        Dec 24 '17 at 15:41
















                      • That may well be true for you, but it isn't really a solution to the stated problem.
                        – bu5hman
                        Dec 24 '17 at 15:41















                      That may well be true for you, but it isn't really a solution to the stated problem.
                      – bu5hman
                      Dec 24 '17 at 15:41




                      That may well be true for you, but it isn't really a solution to the stated problem.
                      – bu5hman
                      Dec 24 '17 at 15:41

















                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














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

                      );

                      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






                      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?