Shell script can be run only with sh command





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







5















I have a small sh script that I use to backup to a remote server. It worked on Ubuntu 16.04 for years, but now on 18.04 it fails. At first I thought it was a problem with anacron, but now I think it is a problem with the script itself or with dash. Here is what is happening:



stefan@stefan-Aspire-F5-573T:/etc/cron.daily$ sudo chmod +x rsync-doc-script 
[sudo] Mot de passe de stefan :
stefan@stefan-Aspire-F5-573T:/etc/cron.daily$ ./rsync-doc-script
/bin/sh: 0: Can't open *
stefan@stefan-Aspire-F5-573T:/etc/cron.daily$ sh rsync-doc-script
opening connection using: ssh -i /home/stefan/.ssh/id_rsa -l totem MouseHouse rsync --server -vvlogDtprze.iLsfxC . /totembackup/totemdoc (11 args)
ssh: connect to host mousehouse port 22: Connection refused
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.2]
stefan@stefan-Aspire-F5-573T:/etc/cron.daily$


The error can't open * is preventing the script from running correctly when run by run-parts. Why is this error occurring?



It is not relevant that in the last line, when the script ran, it couldn't establish connection. The server is turned off now.



Here is the script:



#!/bin/sh                                                                                     *
rsync -azvv -e "ssh -i /home/stefan/.ssh/id_rsa" /home/stefan/Documents/ totem@MouseHouse:/totembackup/totemdoc










share|improve this question





























    5















    I have a small sh script that I use to backup to a remote server. It worked on Ubuntu 16.04 for years, but now on 18.04 it fails. At first I thought it was a problem with anacron, but now I think it is a problem with the script itself or with dash. Here is what is happening:



    stefan@stefan-Aspire-F5-573T:/etc/cron.daily$ sudo chmod +x rsync-doc-script 
    [sudo] Mot de passe de stefan :
    stefan@stefan-Aspire-F5-573T:/etc/cron.daily$ ./rsync-doc-script
    /bin/sh: 0: Can't open *
    stefan@stefan-Aspire-F5-573T:/etc/cron.daily$ sh rsync-doc-script
    opening connection using: ssh -i /home/stefan/.ssh/id_rsa -l totem MouseHouse rsync --server -vvlogDtprze.iLsfxC . /totembackup/totemdoc (11 args)
    ssh: connect to host mousehouse port 22: Connection refused
    rsync: connection unexpectedly closed (0 bytes received so far) [sender]
    rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.2]
    stefan@stefan-Aspire-F5-573T:/etc/cron.daily$


    The error can't open * is preventing the script from running correctly when run by run-parts. Why is this error occurring?



    It is not relevant that in the last line, when the script ran, it couldn't establish connection. The server is turned off now.



    Here is the script:



    #!/bin/sh                                                                                     *
    rsync -azvv -e "ssh -i /home/stefan/.ssh/id_rsa" /home/stefan/Documents/ totem@MouseHouse:/totembackup/totemdoc










    share|improve this question

























      5












      5








      5


      1






      I have a small sh script that I use to backup to a remote server. It worked on Ubuntu 16.04 for years, but now on 18.04 it fails. At first I thought it was a problem with anacron, but now I think it is a problem with the script itself or with dash. Here is what is happening:



      stefan@stefan-Aspire-F5-573T:/etc/cron.daily$ sudo chmod +x rsync-doc-script 
      [sudo] Mot de passe de stefan :
      stefan@stefan-Aspire-F5-573T:/etc/cron.daily$ ./rsync-doc-script
      /bin/sh: 0: Can't open *
      stefan@stefan-Aspire-F5-573T:/etc/cron.daily$ sh rsync-doc-script
      opening connection using: ssh -i /home/stefan/.ssh/id_rsa -l totem MouseHouse rsync --server -vvlogDtprze.iLsfxC . /totembackup/totemdoc (11 args)
      ssh: connect to host mousehouse port 22: Connection refused
      rsync: connection unexpectedly closed (0 bytes received so far) [sender]
      rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.2]
      stefan@stefan-Aspire-F5-573T:/etc/cron.daily$


      The error can't open * is preventing the script from running correctly when run by run-parts. Why is this error occurring?



      It is not relevant that in the last line, when the script ran, it couldn't establish connection. The server is turned off now.



      Here is the script:



      #!/bin/sh                                                                                     *
      rsync -azvv -e "ssh -i /home/stefan/.ssh/id_rsa" /home/stefan/Documents/ totem@MouseHouse:/totembackup/totemdoc










      share|improve this question














      I have a small sh script that I use to backup to a remote server. It worked on Ubuntu 16.04 for years, but now on 18.04 it fails. At first I thought it was a problem with anacron, but now I think it is a problem with the script itself or with dash. Here is what is happening:



      stefan@stefan-Aspire-F5-573T:/etc/cron.daily$ sudo chmod +x rsync-doc-script 
      [sudo] Mot de passe de stefan :
      stefan@stefan-Aspire-F5-573T:/etc/cron.daily$ ./rsync-doc-script
      /bin/sh: 0: Can't open *
      stefan@stefan-Aspire-F5-573T:/etc/cron.daily$ sh rsync-doc-script
      opening connection using: ssh -i /home/stefan/.ssh/id_rsa -l totem MouseHouse rsync --server -vvlogDtprze.iLsfxC . /totembackup/totemdoc (11 args)
      ssh: connect to host mousehouse port 22: Connection refused
      rsync: connection unexpectedly closed (0 bytes received so far) [sender]
      rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.2]
      stefan@stefan-Aspire-F5-573T:/etc/cron.daily$


      The error can't open * is preventing the script from running correctly when run by run-parts. Why is this error occurring?



      It is not relevant that in the last line, when the script ran, it couldn't establish connection. The server is turned off now.



      Here is the script:



      #!/bin/sh                                                                                     *
      rsync -azvv -e "ssh -i /home/stefan/.ssh/id_rsa" /home/stefan/Documents/ totem@MouseHouse:/totembackup/totemdoc







      bash scripts sh






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 7 at 20:23









      Stefan DawydiakStefan Dawydiak

      1465




      1465






















          2 Answers
          2






          active

          oldest

          votes


















          9














          I can't tell for sure but it looks like you have a typo on the first line where there's a stray * over to the right.



          #!/bin/sh                                                                                     *


          ^^^ Scroll over to the right to see it.



          Example



          $ cat script.bash
          #!/bin/sh *
          echo hi


          Run directly:



          $ ./script.bash
          /bin/sh: *: No such file or directory


          Run via sh:



          $ sh script.bash
          hi


          General advice



          It's generally advisable to use the exact shell you're expecting with your shebang. If you suspect that you're running into problems where you suspect dash or some other shell is being used, you can always make your shebang explicit by changing it from #!/bin/sh as your shebang #!/bin/bash.



          The above is based on your comment below:




          but now I think it is a problem with the script itself or with dash.







          share|improve this answer

































            5















            The error can't open * is preventing the script from running correctly
            when run by run-parts. 
            Why is this error occurring?







            When you execute a file1 that is not a binary executable,
            but is a text file with a shebang
            (the first line of the file begins with #!),
            the kernel (with no help from any shell) builds a command
            that is the shebang line (the part after the #!)
            followed by the original, user-level command line. 
            For example, if doc-script begins



            #!/bin/sh -x


            and it is invoked



            ./doc-script bashful dopey


            then the kernel builds and executes the following command:



            /bin/sh -x ./doc-script bashful dopey


            which causes the shell to read and interpret the doc-script script,
            with the xtrace (-x) option set,
            and with $1 = bashful and $2 = dopey
            (Naturally, $0 is ./doc-script.) 
            If the original user-supplied command is



            ./doc-script b* ??p* [ghs]*


            then the shell that handles that command
            (for simplicity, let’s assume that that is the interactive shell
            running on the user’s terminal) might expand this to



            ./doc-script bashful dopey grumpy happy sleepy sneezy


            and so the kernel builds and executes the following command:



            /bin/sh -x ./doc-script bashful dopey grumpy happy sleepy sneezy


            But remember: the processing of the shebang line is done by the kernel,
            not by the shell
            Therefore, if the shebang is



            #!/bin/sh *


            then the final, constructed command is



            /bin/sh * ./doc-script bashful dopey grumpy happy sleepy sneezy


            because glob expansion doesn’t happen here. 
            As far as the shell is concerned, this looks like the user typed



            /bin/sh '*' ./doc-script bashful dopey grumpy happy sleepy sneezy


            and, because * doesn’t begin with -,
            the shell interprets it as a filename,
            so it tries to run a script called * with $0 = *
            $1 = ./doc-script, $2 = bashful, $3 = dopey, etc. 
            And, since there is no script called *, this fails.

            __________
            1 I am assuming that the process
            has the permissions necessary to execute the file.






            share|improve this answer


























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "89"
              };
              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',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              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%2faskubuntu.com%2fquestions%2f1131967%2fshell-script-can-be-run-only-with-sh-command%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              9














              I can't tell for sure but it looks like you have a typo on the first line where there's a stray * over to the right.



              #!/bin/sh                                                                                     *


              ^^^ Scroll over to the right to see it.



              Example



              $ cat script.bash
              #!/bin/sh *
              echo hi


              Run directly:



              $ ./script.bash
              /bin/sh: *: No such file or directory


              Run via sh:



              $ sh script.bash
              hi


              General advice



              It's generally advisable to use the exact shell you're expecting with your shebang. If you suspect that you're running into problems where you suspect dash or some other shell is being used, you can always make your shebang explicit by changing it from #!/bin/sh as your shebang #!/bin/bash.



              The above is based on your comment below:




              but now I think it is a problem with the script itself or with dash.







              share|improve this answer






























                9














                I can't tell for sure but it looks like you have a typo on the first line where there's a stray * over to the right.



                #!/bin/sh                                                                                     *


                ^^^ Scroll over to the right to see it.



                Example



                $ cat script.bash
                #!/bin/sh *
                echo hi


                Run directly:



                $ ./script.bash
                /bin/sh: *: No such file or directory


                Run via sh:



                $ sh script.bash
                hi


                General advice



                It's generally advisable to use the exact shell you're expecting with your shebang. If you suspect that you're running into problems where you suspect dash or some other shell is being used, you can always make your shebang explicit by changing it from #!/bin/sh as your shebang #!/bin/bash.



                The above is based on your comment below:




                but now I think it is a problem with the script itself or with dash.







                share|improve this answer




























                  9












                  9








                  9







                  I can't tell for sure but it looks like you have a typo on the first line where there's a stray * over to the right.



                  #!/bin/sh                                                                                     *


                  ^^^ Scroll over to the right to see it.



                  Example



                  $ cat script.bash
                  #!/bin/sh *
                  echo hi


                  Run directly:



                  $ ./script.bash
                  /bin/sh: *: No such file or directory


                  Run via sh:



                  $ sh script.bash
                  hi


                  General advice



                  It's generally advisable to use the exact shell you're expecting with your shebang. If you suspect that you're running into problems where you suspect dash or some other shell is being used, you can always make your shebang explicit by changing it from #!/bin/sh as your shebang #!/bin/bash.



                  The above is based on your comment below:




                  but now I think it is a problem with the script itself or with dash.







                  share|improve this answer















                  I can't tell for sure but it looks like you have a typo on the first line where there's a stray * over to the right.



                  #!/bin/sh                                                                                     *


                  ^^^ Scroll over to the right to see it.



                  Example



                  $ cat script.bash
                  #!/bin/sh *
                  echo hi


                  Run directly:



                  $ ./script.bash
                  /bin/sh: *: No such file or directory


                  Run via sh:



                  $ sh script.bash
                  hi


                  General advice



                  It's generally advisable to use the exact shell you're expecting with your shebang. If you suspect that you're running into problems where you suspect dash or some other shell is being used, you can always make your shebang explicit by changing it from #!/bin/sh as your shebang #!/bin/bash.



                  The above is based on your comment below:




                  but now I think it is a problem with the script itself or with dash.








                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Apr 8 at 12:26

























                  answered Apr 7 at 20:25









                  slmslm

                  2,01811826




                  2,01811826

























                      5















                      The error can't open * is preventing the script from running correctly
                      when run by run-parts. 
                      Why is this error occurring?







                      When you execute a file1 that is not a binary executable,
                      but is a text file with a shebang
                      (the first line of the file begins with #!),
                      the kernel (with no help from any shell) builds a command
                      that is the shebang line (the part after the #!)
                      followed by the original, user-level command line. 
                      For example, if doc-script begins



                      #!/bin/sh -x


                      and it is invoked



                      ./doc-script bashful dopey


                      then the kernel builds and executes the following command:



                      /bin/sh -x ./doc-script bashful dopey


                      which causes the shell to read and interpret the doc-script script,
                      with the xtrace (-x) option set,
                      and with $1 = bashful and $2 = dopey
                      (Naturally, $0 is ./doc-script.) 
                      If the original user-supplied command is



                      ./doc-script b* ??p* [ghs]*


                      then the shell that handles that command
                      (for simplicity, let’s assume that that is the interactive shell
                      running on the user’s terminal) might expand this to



                      ./doc-script bashful dopey grumpy happy sleepy sneezy


                      and so the kernel builds and executes the following command:



                      /bin/sh -x ./doc-script bashful dopey grumpy happy sleepy sneezy


                      But remember: the processing of the shebang line is done by the kernel,
                      not by the shell
                      Therefore, if the shebang is



                      #!/bin/sh *


                      then the final, constructed command is



                      /bin/sh * ./doc-script bashful dopey grumpy happy sleepy sneezy


                      because glob expansion doesn’t happen here. 
                      As far as the shell is concerned, this looks like the user typed



                      /bin/sh '*' ./doc-script bashful dopey grumpy happy sleepy sneezy


                      and, because * doesn’t begin with -,
                      the shell interprets it as a filename,
                      so it tries to run a script called * with $0 = *
                      $1 = ./doc-script, $2 = bashful, $3 = dopey, etc. 
                      And, since there is no script called *, this fails.

                      __________
                      1 I am assuming that the process
                      has the permissions necessary to execute the file.






                      share|improve this answer






























                        5















                        The error can't open * is preventing the script from running correctly
                        when run by run-parts. 
                        Why is this error occurring?







                        When you execute a file1 that is not a binary executable,
                        but is a text file with a shebang
                        (the first line of the file begins with #!),
                        the kernel (with no help from any shell) builds a command
                        that is the shebang line (the part after the #!)
                        followed by the original, user-level command line. 
                        For example, if doc-script begins



                        #!/bin/sh -x


                        and it is invoked



                        ./doc-script bashful dopey


                        then the kernel builds and executes the following command:



                        /bin/sh -x ./doc-script bashful dopey


                        which causes the shell to read and interpret the doc-script script,
                        with the xtrace (-x) option set,
                        and with $1 = bashful and $2 = dopey
                        (Naturally, $0 is ./doc-script.) 
                        If the original user-supplied command is



                        ./doc-script b* ??p* [ghs]*


                        then the shell that handles that command
                        (for simplicity, let’s assume that that is the interactive shell
                        running on the user’s terminal) might expand this to



                        ./doc-script bashful dopey grumpy happy sleepy sneezy


                        and so the kernel builds and executes the following command:



                        /bin/sh -x ./doc-script bashful dopey grumpy happy sleepy sneezy


                        But remember: the processing of the shebang line is done by the kernel,
                        not by the shell
                        Therefore, if the shebang is



                        #!/bin/sh *


                        then the final, constructed command is



                        /bin/sh * ./doc-script bashful dopey grumpy happy sleepy sneezy


                        because glob expansion doesn’t happen here. 
                        As far as the shell is concerned, this looks like the user typed



                        /bin/sh '*' ./doc-script bashful dopey grumpy happy sleepy sneezy


                        and, because * doesn’t begin with -,
                        the shell interprets it as a filename,
                        so it tries to run a script called * with $0 = *
                        $1 = ./doc-script, $2 = bashful, $3 = dopey, etc. 
                        And, since there is no script called *, this fails.

                        __________
                        1 I am assuming that the process
                        has the permissions necessary to execute the file.






                        share|improve this answer




























                          5












                          5








                          5








                          The error can't open * is preventing the script from running correctly
                          when run by run-parts. 
                          Why is this error occurring?







                          When you execute a file1 that is not a binary executable,
                          but is a text file with a shebang
                          (the first line of the file begins with #!),
                          the kernel (with no help from any shell) builds a command
                          that is the shebang line (the part after the #!)
                          followed by the original, user-level command line. 
                          For example, if doc-script begins



                          #!/bin/sh -x


                          and it is invoked



                          ./doc-script bashful dopey


                          then the kernel builds and executes the following command:



                          /bin/sh -x ./doc-script bashful dopey


                          which causes the shell to read and interpret the doc-script script,
                          with the xtrace (-x) option set,
                          and with $1 = bashful and $2 = dopey
                          (Naturally, $0 is ./doc-script.) 
                          If the original user-supplied command is



                          ./doc-script b* ??p* [ghs]*


                          then the shell that handles that command
                          (for simplicity, let’s assume that that is the interactive shell
                          running on the user’s terminal) might expand this to



                          ./doc-script bashful dopey grumpy happy sleepy sneezy


                          and so the kernel builds and executes the following command:



                          /bin/sh -x ./doc-script bashful dopey grumpy happy sleepy sneezy


                          But remember: the processing of the shebang line is done by the kernel,
                          not by the shell
                          Therefore, if the shebang is



                          #!/bin/sh *


                          then the final, constructed command is



                          /bin/sh * ./doc-script bashful dopey grumpy happy sleepy sneezy


                          because glob expansion doesn’t happen here. 
                          As far as the shell is concerned, this looks like the user typed



                          /bin/sh '*' ./doc-script bashful dopey grumpy happy sleepy sneezy


                          and, because * doesn’t begin with -,
                          the shell interprets it as a filename,
                          so it tries to run a script called * with $0 = *
                          $1 = ./doc-script, $2 = bashful, $3 = dopey, etc. 
                          And, since there is no script called *, this fails.

                          __________
                          1 I am assuming that the process
                          has the permissions necessary to execute the file.






                          share|improve this answer
















                          The error can't open * is preventing the script from running correctly
                          when run by run-parts. 
                          Why is this error occurring?







                          When you execute a file1 that is not a binary executable,
                          but is a text file with a shebang
                          (the first line of the file begins with #!),
                          the kernel (with no help from any shell) builds a command
                          that is the shebang line (the part after the #!)
                          followed by the original, user-level command line. 
                          For example, if doc-script begins



                          #!/bin/sh -x


                          and it is invoked



                          ./doc-script bashful dopey


                          then the kernel builds and executes the following command:



                          /bin/sh -x ./doc-script bashful dopey


                          which causes the shell to read and interpret the doc-script script,
                          with the xtrace (-x) option set,
                          and with $1 = bashful and $2 = dopey
                          (Naturally, $0 is ./doc-script.) 
                          If the original user-supplied command is



                          ./doc-script b* ??p* [ghs]*


                          then the shell that handles that command
                          (for simplicity, let’s assume that that is the interactive shell
                          running on the user’s terminal) might expand this to



                          ./doc-script bashful dopey grumpy happy sleepy sneezy


                          and so the kernel builds and executes the following command:



                          /bin/sh -x ./doc-script bashful dopey grumpy happy sleepy sneezy


                          But remember: the processing of the shebang line is done by the kernel,
                          not by the shell
                          Therefore, if the shebang is



                          #!/bin/sh *


                          then the final, constructed command is



                          /bin/sh * ./doc-script bashful dopey grumpy happy sleepy sneezy


                          because glob expansion doesn’t happen here. 
                          As far as the shell is concerned, this looks like the user typed



                          /bin/sh '*' ./doc-script bashful dopey grumpy happy sleepy sneezy


                          and, because * doesn’t begin with -,
                          the shell interprets it as a filename,
                          so it tries to run a script called * with $0 = *
                          $1 = ./doc-script, $2 = bashful, $3 = dopey, etc. 
                          And, since there is no script called *, this fails.

                          __________
                          1 I am assuming that the process
                          has the permissions necessary to execute the file.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Apr 11 at 3:32

























                          answered Apr 8 at 5:56









                          G-ManG-Man

                          591510




                          591510






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Ask Ubuntu!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1131967%2fshell-script-can-be-run-only-with-sh-command%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

                              Plaza Victoria

                              In PowerPoint, is there a keyboard shortcut for bulleted / numbered list?

                              How to put 3 figures in Latex with 2 figures side by side and 1 below these side by side images but in...