fish shell : exec format error












2














On an Ubuntu ($ uname -a : Linux kumanaku 4.15.0-43-generic #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux), I just installed fish ($ fish --version : fish, version 2.7.1) using the following commands :



sudo apt-add-repository ppa:fish-shell/release-2
sudo apt-get update
sudo apt-get install fish
chsh -s /usr/bin/fish
echo /usr/bin/fish | sudo tee -a /etc/shells


I can launch fish and use it but when I launch a simple shell file like :



echo "something"


I got the following message :



$ ./myscript.sh

Failed to execute process './myscript.sh'. Reason:
exec: Exec format error
The file './myscript.sh' is marked as an executable but could not be run by the operating system.


There's no shebang in my script. If I add #!/usr/bin/env fish, everything's ok (i.e. the script is successfully launched) but I'd like to avoid such a line to keep my script compatible with different shells.



Any idea ?










share|improve this question




















  • 1




    Related: Which shell interpreter runs a script with no shebang?
    – Michael Homer
    Dec 29 '18 at 7:06






  • 1




    (the takeaway is that fish does not attempt POSIX compatibility there, so launching scripts from fish requires that execvp succeeds)
    – Michael Homer
    Dec 29 '18 at 7:08
















2














On an Ubuntu ($ uname -a : Linux kumanaku 4.15.0-43-generic #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux), I just installed fish ($ fish --version : fish, version 2.7.1) using the following commands :



sudo apt-add-repository ppa:fish-shell/release-2
sudo apt-get update
sudo apt-get install fish
chsh -s /usr/bin/fish
echo /usr/bin/fish | sudo tee -a /etc/shells


I can launch fish and use it but when I launch a simple shell file like :



echo "something"


I got the following message :



$ ./myscript.sh

Failed to execute process './myscript.sh'. Reason:
exec: Exec format error
The file './myscript.sh' is marked as an executable but could not be run by the operating system.


There's no shebang in my script. If I add #!/usr/bin/env fish, everything's ok (i.e. the script is successfully launched) but I'd like to avoid such a line to keep my script compatible with different shells.



Any idea ?










share|improve this question




















  • 1




    Related: Which shell interpreter runs a script with no shebang?
    – Michael Homer
    Dec 29 '18 at 7:06






  • 1




    (the takeaway is that fish does not attempt POSIX compatibility there, so launching scripts from fish requires that execvp succeeds)
    – Michael Homer
    Dec 29 '18 at 7:08














2












2








2







On an Ubuntu ($ uname -a : Linux kumanaku 4.15.0-43-generic #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux), I just installed fish ($ fish --version : fish, version 2.7.1) using the following commands :



sudo apt-add-repository ppa:fish-shell/release-2
sudo apt-get update
sudo apt-get install fish
chsh -s /usr/bin/fish
echo /usr/bin/fish | sudo tee -a /etc/shells


I can launch fish and use it but when I launch a simple shell file like :



echo "something"


I got the following message :



$ ./myscript.sh

Failed to execute process './myscript.sh'. Reason:
exec: Exec format error
The file './myscript.sh' is marked as an executable but could not be run by the operating system.


There's no shebang in my script. If I add #!/usr/bin/env fish, everything's ok (i.e. the script is successfully launched) but I'd like to avoid such a line to keep my script compatible with different shells.



Any idea ?










share|improve this question















On an Ubuntu ($ uname -a : Linux kumanaku 4.15.0-43-generic #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux), I just installed fish ($ fish --version : fish, version 2.7.1) using the following commands :



sudo apt-add-repository ppa:fish-shell/release-2
sudo apt-get update
sudo apt-get install fish
chsh -s /usr/bin/fish
echo /usr/bin/fish | sudo tee -a /etc/shells


I can launch fish and use it but when I launch a simple shell file like :



echo "something"


I got the following message :



$ ./myscript.sh

Failed to execute process './myscript.sh'. Reason:
exec: Exec format error
The file './myscript.sh' is marked as an executable but could not be run by the operating system.


There's no shebang in my script. If I add #!/usr/bin/env fish, everything's ok (i.e. the script is successfully launched) but I'd like to avoid such a line to keep my script compatible with different shells.



Any idea ?







shell-script shell fish






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









Rui F Ribeiro

39k1479129




39k1479129










asked Dec 29 '18 at 6:44









suizokukan

1184




1184








  • 1




    Related: Which shell interpreter runs a script with no shebang?
    – Michael Homer
    Dec 29 '18 at 7:06






  • 1




    (the takeaway is that fish does not attempt POSIX compatibility there, so launching scripts from fish requires that execvp succeeds)
    – Michael Homer
    Dec 29 '18 at 7:08














  • 1




    Related: Which shell interpreter runs a script with no shebang?
    – Michael Homer
    Dec 29 '18 at 7:06






  • 1




    (the takeaway is that fish does not attempt POSIX compatibility there, so launching scripts from fish requires that execvp succeeds)
    – Michael Homer
    Dec 29 '18 at 7:08








1




1




Related: Which shell interpreter runs a script with no shebang?
– Michael Homer
Dec 29 '18 at 7:06




Related: Which shell interpreter runs a script with no shebang?
– Michael Homer
Dec 29 '18 at 7:06




1




1




(the takeaway is that fish does not attempt POSIX compatibility there, so launching scripts from fish requires that execvp succeeds)
– Michael Homer
Dec 29 '18 at 7:08




(the takeaway is that fish does not attempt POSIX compatibility there, so launching scripts from fish requires that execvp succeeds)
– Michael Homer
Dec 29 '18 at 7:08










2 Answers
2






active

oldest

votes


















3














You need to have a shebang in order to execute a script by referencing its path. Otherwise, the operating system will attempt to execute it, but will fail because it's not a binary executable file.



If you don't want to use a shebang you need to specify what should execute the script. In your case, it should be fish.



fish myscript.sh






share|improve this answer





















  • Ok, so I'm looking for a 'universal' shebang. What about #!/usr/bin/env bash (see stackoverflow.com/questions/10376206/…) ? This line allows my script to be launched directly with fish.
    – suizokukan
    Dec 29 '18 at 7:14






  • 1




    @suizokukan: #!/usr/bin/env bash is only universal if every system you want to execute the script has bash installed. If you want portability, write your script to be compatible with POSIX standards. Then most shells will be able to execute it without issue (as most common shells are POSIX compliant).
    – Peschke
    Dec 29 '18 at 7:31








  • 2




    POSIX scripts don't have the shebang, and since fish isn't POSIX-compatible it can't call them anyway (the premise of this question), so I'm not sure that helps
    – Michael Homer
    2 days ago






  • 2




    @MichaelHomer: POSIX scripts can have a shebang if you want them to. Since OP later asked for a ‘universal’ shebang, #!/bin/sh would be the way to go in my opinion.
    – Peschke
    2 days ago



















3














You need a shebang line if the executable file cannot be run natively by the kernel. The kernel can only run machine code in a specific format (ELF on most Unix variants), or sometimes other formats (e.g. on Linux you can register executable formats through binfmt_misc). If the executable file needs an interpreter then the kernel needs to know which interpreter to call. That's what the shebang line is for.



If your script is in fish syntax, its first line must be



#!/usr/bin/env fish


(You can use the absolute path instead, but then you'll have to modify the script if you want to run it on a machine where the fish executable is in a different location, e.g. /usr/bin/fish vs /usr/local/bin/fish.)



If your script is in sh syntax, use



#!/bin/sh


(All modern Unix systems have a POSIX sh at /bin/sh so you don't need env.)



If your script is in bash syntax (which is sh plus some bash-specific extensions), use



#!/usr/bin/env bash


On Linux, in practice, #!/bin/bash will also work.



All of this is independent of which shell you're calling the script from. All that matters is what language the script is written in.






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',
    autoActivateHeartbeat: false,
    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%2f491419%2ffish-shell-exec-format-error%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









    3














    You need to have a shebang in order to execute a script by referencing its path. Otherwise, the operating system will attempt to execute it, but will fail because it's not a binary executable file.



    If you don't want to use a shebang you need to specify what should execute the script. In your case, it should be fish.



    fish myscript.sh






    share|improve this answer





















    • Ok, so I'm looking for a 'universal' shebang. What about #!/usr/bin/env bash (see stackoverflow.com/questions/10376206/…) ? This line allows my script to be launched directly with fish.
      – suizokukan
      Dec 29 '18 at 7:14






    • 1




      @suizokukan: #!/usr/bin/env bash is only universal if every system you want to execute the script has bash installed. If you want portability, write your script to be compatible with POSIX standards. Then most shells will be able to execute it without issue (as most common shells are POSIX compliant).
      – Peschke
      Dec 29 '18 at 7:31








    • 2




      POSIX scripts don't have the shebang, and since fish isn't POSIX-compatible it can't call them anyway (the premise of this question), so I'm not sure that helps
      – Michael Homer
      2 days ago






    • 2




      @MichaelHomer: POSIX scripts can have a shebang if you want them to. Since OP later asked for a ‘universal’ shebang, #!/bin/sh would be the way to go in my opinion.
      – Peschke
      2 days ago
















    3














    You need to have a shebang in order to execute a script by referencing its path. Otherwise, the operating system will attempt to execute it, but will fail because it's not a binary executable file.



    If you don't want to use a shebang you need to specify what should execute the script. In your case, it should be fish.



    fish myscript.sh






    share|improve this answer





















    • Ok, so I'm looking for a 'universal' shebang. What about #!/usr/bin/env bash (see stackoverflow.com/questions/10376206/…) ? This line allows my script to be launched directly with fish.
      – suizokukan
      Dec 29 '18 at 7:14






    • 1




      @suizokukan: #!/usr/bin/env bash is only universal if every system you want to execute the script has bash installed. If you want portability, write your script to be compatible with POSIX standards. Then most shells will be able to execute it without issue (as most common shells are POSIX compliant).
      – Peschke
      Dec 29 '18 at 7:31








    • 2




      POSIX scripts don't have the shebang, and since fish isn't POSIX-compatible it can't call them anyway (the premise of this question), so I'm not sure that helps
      – Michael Homer
      2 days ago






    • 2




      @MichaelHomer: POSIX scripts can have a shebang if you want them to. Since OP later asked for a ‘universal’ shebang, #!/bin/sh would be the way to go in my opinion.
      – Peschke
      2 days ago














    3












    3








    3






    You need to have a shebang in order to execute a script by referencing its path. Otherwise, the operating system will attempt to execute it, but will fail because it's not a binary executable file.



    If you don't want to use a shebang you need to specify what should execute the script. In your case, it should be fish.



    fish myscript.sh






    share|improve this answer












    You need to have a shebang in order to execute a script by referencing its path. Otherwise, the operating system will attempt to execute it, but will fail because it's not a binary executable file.



    If you don't want to use a shebang you need to specify what should execute the script. In your case, it should be fish.



    fish myscript.sh







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Dec 29 '18 at 7:03









    Peschke

    2,493924




    2,493924












    • Ok, so I'm looking for a 'universal' shebang. What about #!/usr/bin/env bash (see stackoverflow.com/questions/10376206/…) ? This line allows my script to be launched directly with fish.
      – suizokukan
      Dec 29 '18 at 7:14






    • 1




      @suizokukan: #!/usr/bin/env bash is only universal if every system you want to execute the script has bash installed. If you want portability, write your script to be compatible with POSIX standards. Then most shells will be able to execute it without issue (as most common shells are POSIX compliant).
      – Peschke
      Dec 29 '18 at 7:31








    • 2




      POSIX scripts don't have the shebang, and since fish isn't POSIX-compatible it can't call them anyway (the premise of this question), so I'm not sure that helps
      – Michael Homer
      2 days ago






    • 2




      @MichaelHomer: POSIX scripts can have a shebang if you want them to. Since OP later asked for a ‘universal’ shebang, #!/bin/sh would be the way to go in my opinion.
      – Peschke
      2 days ago


















    • Ok, so I'm looking for a 'universal' shebang. What about #!/usr/bin/env bash (see stackoverflow.com/questions/10376206/…) ? This line allows my script to be launched directly with fish.
      – suizokukan
      Dec 29 '18 at 7:14






    • 1




      @suizokukan: #!/usr/bin/env bash is only universal if every system you want to execute the script has bash installed. If you want portability, write your script to be compatible with POSIX standards. Then most shells will be able to execute it without issue (as most common shells are POSIX compliant).
      – Peschke
      Dec 29 '18 at 7:31








    • 2




      POSIX scripts don't have the shebang, and since fish isn't POSIX-compatible it can't call them anyway (the premise of this question), so I'm not sure that helps
      – Michael Homer
      2 days ago






    • 2




      @MichaelHomer: POSIX scripts can have a shebang if you want them to. Since OP later asked for a ‘universal’ shebang, #!/bin/sh would be the way to go in my opinion.
      – Peschke
      2 days ago
















    Ok, so I'm looking for a 'universal' shebang. What about #!/usr/bin/env bash (see stackoverflow.com/questions/10376206/…) ? This line allows my script to be launched directly with fish.
    – suizokukan
    Dec 29 '18 at 7:14




    Ok, so I'm looking for a 'universal' shebang. What about #!/usr/bin/env bash (see stackoverflow.com/questions/10376206/…) ? This line allows my script to be launched directly with fish.
    – suizokukan
    Dec 29 '18 at 7:14




    1




    1




    @suizokukan: #!/usr/bin/env bash is only universal if every system you want to execute the script has bash installed. If you want portability, write your script to be compatible with POSIX standards. Then most shells will be able to execute it without issue (as most common shells are POSIX compliant).
    – Peschke
    Dec 29 '18 at 7:31






    @suizokukan: #!/usr/bin/env bash is only universal if every system you want to execute the script has bash installed. If you want portability, write your script to be compatible with POSIX standards. Then most shells will be able to execute it without issue (as most common shells are POSIX compliant).
    – Peschke
    Dec 29 '18 at 7:31






    2




    2




    POSIX scripts don't have the shebang, and since fish isn't POSIX-compatible it can't call them anyway (the premise of this question), so I'm not sure that helps
    – Michael Homer
    2 days ago




    POSIX scripts don't have the shebang, and since fish isn't POSIX-compatible it can't call them anyway (the premise of this question), so I'm not sure that helps
    – Michael Homer
    2 days ago




    2




    2




    @MichaelHomer: POSIX scripts can have a shebang if you want them to. Since OP later asked for a ‘universal’ shebang, #!/bin/sh would be the way to go in my opinion.
    – Peschke
    2 days ago




    @MichaelHomer: POSIX scripts can have a shebang if you want them to. Since OP later asked for a ‘universal’ shebang, #!/bin/sh would be the way to go in my opinion.
    – Peschke
    2 days ago













    3














    You need a shebang line if the executable file cannot be run natively by the kernel. The kernel can only run machine code in a specific format (ELF on most Unix variants), or sometimes other formats (e.g. on Linux you can register executable formats through binfmt_misc). If the executable file needs an interpreter then the kernel needs to know which interpreter to call. That's what the shebang line is for.



    If your script is in fish syntax, its first line must be



    #!/usr/bin/env fish


    (You can use the absolute path instead, but then you'll have to modify the script if you want to run it on a machine where the fish executable is in a different location, e.g. /usr/bin/fish vs /usr/local/bin/fish.)



    If your script is in sh syntax, use



    #!/bin/sh


    (All modern Unix systems have a POSIX sh at /bin/sh so you don't need env.)



    If your script is in bash syntax (which is sh plus some bash-specific extensions), use



    #!/usr/bin/env bash


    On Linux, in practice, #!/bin/bash will also work.



    All of this is independent of which shell you're calling the script from. All that matters is what language the script is written in.






    share|improve this answer


























      3














      You need a shebang line if the executable file cannot be run natively by the kernel. The kernel can only run machine code in a specific format (ELF on most Unix variants), or sometimes other formats (e.g. on Linux you can register executable formats through binfmt_misc). If the executable file needs an interpreter then the kernel needs to know which interpreter to call. That's what the shebang line is for.



      If your script is in fish syntax, its first line must be



      #!/usr/bin/env fish


      (You can use the absolute path instead, but then you'll have to modify the script if you want to run it on a machine where the fish executable is in a different location, e.g. /usr/bin/fish vs /usr/local/bin/fish.)



      If your script is in sh syntax, use



      #!/bin/sh


      (All modern Unix systems have a POSIX sh at /bin/sh so you don't need env.)



      If your script is in bash syntax (which is sh plus some bash-specific extensions), use



      #!/usr/bin/env bash


      On Linux, in practice, #!/bin/bash will also work.



      All of this is independent of which shell you're calling the script from. All that matters is what language the script is written in.






      share|improve this answer
























        3












        3








        3






        You need a shebang line if the executable file cannot be run natively by the kernel. The kernel can only run machine code in a specific format (ELF on most Unix variants), or sometimes other formats (e.g. on Linux you can register executable formats through binfmt_misc). If the executable file needs an interpreter then the kernel needs to know which interpreter to call. That's what the shebang line is for.



        If your script is in fish syntax, its first line must be



        #!/usr/bin/env fish


        (You can use the absolute path instead, but then you'll have to modify the script if you want to run it on a machine where the fish executable is in a different location, e.g. /usr/bin/fish vs /usr/local/bin/fish.)



        If your script is in sh syntax, use



        #!/bin/sh


        (All modern Unix systems have a POSIX sh at /bin/sh so you don't need env.)



        If your script is in bash syntax (which is sh plus some bash-specific extensions), use



        #!/usr/bin/env bash


        On Linux, in practice, #!/bin/bash will also work.



        All of this is independent of which shell you're calling the script from. All that matters is what language the script is written in.






        share|improve this answer












        You need a shebang line if the executable file cannot be run natively by the kernel. The kernel can only run machine code in a specific format (ELF on most Unix variants), or sometimes other formats (e.g. on Linux you can register executable formats through binfmt_misc). If the executable file needs an interpreter then the kernel needs to know which interpreter to call. That's what the shebang line is for.



        If your script is in fish syntax, its first line must be



        #!/usr/bin/env fish


        (You can use the absolute path instead, but then you'll have to modify the script if you want to run it on a machine where the fish executable is in a different location, e.g. /usr/bin/fish vs /usr/local/bin/fish.)



        If your script is in sh syntax, use



        #!/bin/sh


        (All modern Unix systems have a POSIX sh at /bin/sh so you don't need env.)



        If your script is in bash syntax (which is sh plus some bash-specific extensions), use



        #!/usr/bin/env bash


        On Linux, in practice, #!/bin/bash will also work.



        All of this is independent of which shell you're calling the script from. All that matters is what language the script is written in.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        Gilles

        528k12810581583




        528k12810581583






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


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





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2funix.stackexchange.com%2fquestions%2f491419%2ffish-shell-exec-format-error%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

            "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

            Alcedinidae

            RAC Tourist Trophy