Different ways to execute a binary? [on hold]











up vote
0
down vote

favorite












Are there more ways of executing Unix binaries using a terminal (command line)? Using echo as an example:



$ /bin/echo "test"
test

$ cd /bin/
$ ./echo "test"
test

$ eval echo "test"
test









share|improve this question









New contributor




user321532 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as unclear what you're asking by Scott, Romeo Ninov, Michael Homer, Sparhawk, Wieland Nov 18 at 8:54


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.











  • 2




    cd /; bin/echo "test", cd /usr/share; ../../var/log/../../bin/echo test. If we take your two first examples as distinct, then the possibilities are endless!
    – Sparhawk
    Nov 18 at 3:56










  • do you mean "ways to execute it from a shell" or do you also mean to also include ways that are not from a shell, such as in a program that is not a shell script?
    – Skaperen
    Nov 18 at 4:29










  • execute from a shell/terminal, yeah. ill update the question. your comment was very helpful actually.
    – user321532
    Nov 18 at 4:31










  • which shell are you using? there are many and each has their own ways. and there are an "infinite" number of ways to construct commands in each of the many shells.
    – Skaperen
    Nov 18 at 4:48










  • i dont get how a similar question has been asked before and received +43 but i ask it (specific to binaries, not bash) and it gets -1? thanks anyway unix.stackexchange.com/questions/2976
    – user321532
    Nov 18 at 5:17















up vote
0
down vote

favorite












Are there more ways of executing Unix binaries using a terminal (command line)? Using echo as an example:



$ /bin/echo "test"
test

$ cd /bin/
$ ./echo "test"
test

$ eval echo "test"
test









share|improve this question









New contributor




user321532 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as unclear what you're asking by Scott, Romeo Ninov, Michael Homer, Sparhawk, Wieland Nov 18 at 8:54


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.











  • 2




    cd /; bin/echo "test", cd /usr/share; ../../var/log/../../bin/echo test. If we take your two first examples as distinct, then the possibilities are endless!
    – Sparhawk
    Nov 18 at 3:56










  • do you mean "ways to execute it from a shell" or do you also mean to also include ways that are not from a shell, such as in a program that is not a shell script?
    – Skaperen
    Nov 18 at 4:29










  • execute from a shell/terminal, yeah. ill update the question. your comment was very helpful actually.
    – user321532
    Nov 18 at 4:31










  • which shell are you using? there are many and each has their own ways. and there are an "infinite" number of ways to construct commands in each of the many shells.
    – Skaperen
    Nov 18 at 4:48










  • i dont get how a similar question has been asked before and received +43 but i ask it (specific to binaries, not bash) and it gets -1? thanks anyway unix.stackexchange.com/questions/2976
    – user321532
    Nov 18 at 5:17













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Are there more ways of executing Unix binaries using a terminal (command line)? Using echo as an example:



$ /bin/echo "test"
test

$ cd /bin/
$ ./echo "test"
test

$ eval echo "test"
test









share|improve this question









New contributor




user321532 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











Are there more ways of executing Unix binaries using a terminal (command line)? Using echo as an example:



$ /bin/echo "test"
test

$ cd /bin/
$ ./echo "test"
test

$ eval echo "test"
test






linux ubuntu command-line terminal osx






share|improve this question









New contributor




user321532 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




user321532 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 18 at 4:31





















New contributor




user321532 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 18 at 3:48









user321532

61




61




New contributor




user321532 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





user321532 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






user321532 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as unclear what you're asking by Scott, Romeo Ninov, Michael Homer, Sparhawk, Wieland Nov 18 at 8:54


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






put on hold as unclear what you're asking by Scott, Romeo Ninov, Michael Homer, Sparhawk, Wieland Nov 18 at 8:54


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 2




    cd /; bin/echo "test", cd /usr/share; ../../var/log/../../bin/echo test. If we take your two first examples as distinct, then the possibilities are endless!
    – Sparhawk
    Nov 18 at 3:56










  • do you mean "ways to execute it from a shell" or do you also mean to also include ways that are not from a shell, such as in a program that is not a shell script?
    – Skaperen
    Nov 18 at 4:29










  • execute from a shell/terminal, yeah. ill update the question. your comment was very helpful actually.
    – user321532
    Nov 18 at 4:31










  • which shell are you using? there are many and each has their own ways. and there are an "infinite" number of ways to construct commands in each of the many shells.
    – Skaperen
    Nov 18 at 4:48










  • i dont get how a similar question has been asked before and received +43 but i ask it (specific to binaries, not bash) and it gets -1? thanks anyway unix.stackexchange.com/questions/2976
    – user321532
    Nov 18 at 5:17














  • 2




    cd /; bin/echo "test", cd /usr/share; ../../var/log/../../bin/echo test. If we take your two first examples as distinct, then the possibilities are endless!
    – Sparhawk
    Nov 18 at 3:56










  • do you mean "ways to execute it from a shell" or do you also mean to also include ways that are not from a shell, such as in a program that is not a shell script?
    – Skaperen
    Nov 18 at 4:29










  • execute from a shell/terminal, yeah. ill update the question. your comment was very helpful actually.
    – user321532
    Nov 18 at 4:31










  • which shell are you using? there are many and each has their own ways. and there are an "infinite" number of ways to construct commands in each of the many shells.
    – Skaperen
    Nov 18 at 4:48










  • i dont get how a similar question has been asked before and received +43 but i ask it (specific to binaries, not bash) and it gets -1? thanks anyway unix.stackexchange.com/questions/2976
    – user321532
    Nov 18 at 5:17








2




2




cd /; bin/echo "test", cd /usr/share; ../../var/log/../../bin/echo test. If we take your two first examples as distinct, then the possibilities are endless!
– Sparhawk
Nov 18 at 3:56




cd /; bin/echo "test", cd /usr/share; ../../var/log/../../bin/echo test. If we take your two first examples as distinct, then the possibilities are endless!
– Sparhawk
Nov 18 at 3:56












do you mean "ways to execute it from a shell" or do you also mean to also include ways that are not from a shell, such as in a program that is not a shell script?
– Skaperen
Nov 18 at 4:29




do you mean "ways to execute it from a shell" or do you also mean to also include ways that are not from a shell, such as in a program that is not a shell script?
– Skaperen
Nov 18 at 4:29












execute from a shell/terminal, yeah. ill update the question. your comment was very helpful actually.
– user321532
Nov 18 at 4:31




execute from a shell/terminal, yeah. ill update the question. your comment was very helpful actually.
– user321532
Nov 18 at 4:31












which shell are you using? there are many and each has their own ways. and there are an "infinite" number of ways to construct commands in each of the many shells.
– Skaperen
Nov 18 at 4:48




which shell are you using? there are many and each has their own ways. and there are an "infinite" number of ways to construct commands in each of the many shells.
– Skaperen
Nov 18 at 4:48












i dont get how a similar question has been asked before and received +43 but i ask it (specific to binaries, not bash) and it gets -1? thanks anyway unix.stackexchange.com/questions/2976
– user321532
Nov 18 at 5:17




i dont get how a similar question has been asked before and received +43 but i ask it (specific to binaries, not bash) and it gets -1? thanks anyway unix.stackexchange.com/questions/2976
– user321532
Nov 18 at 5:17










2 Answers
2






active

oldest

votes

















up vote
1
down vote













There many different ways to express code in a shell command line or in a shell script line that can result in a binary being executed. They all just come down to the point of running a shell command. The shell will try to run a file if the command refers to a file. That attempt will succeed if you have permission to execute the file. The file may be a binary executable or a script that refers to its interpreter on the first line (which begins with "#!") or the file may just be plain data like text. If it is executable at that point then it will run or be interpreted. The shell has plenty of ways to express a command. The possibilities are infinite.






share|improve this answer




























    up vote
    1
    down vote













    Please note that, as Sparhawk pointed out in the comments, the first two examples are doing basically the same (they invoke the program using its path instead of doing a path lookup) and following that logic the ways to execute a given program are virtually infinite.



    Anyway, I'd say there are at least 4 different ways to execute programs[1] from a shell:





    • Shell builtins: some commands, such as echo itself in Bash, are implemented within the shell so the corresponding external utility, if exists, is not invoked.



      $ echo foo
      foo



    • Path lookup: when the shell searches the desired program in each of the directories included in the PATH environment variable.



      $ cat <<< foo
      foo



    • Direct invoking: when the program is invoked using its full/relative path.



      $ /bin/echo foo
      foo




      $ ../../bin/echo foo
      foo



    • Indirect invoking: when the program is invoked by another program (either a builtin or an external one).



      $ eval echo foo
      foo




      $ command echo foo
      foo




      $ sh -c 'echo foo'
      foo






    1. I know you said binaries. I used a more general term because scripts can also be executed from a shell.






    share|improve this answer

















    • 1




      a reference to a file to be executed works the same whether the file is a script or a binary. except for sourcing the shell doesn't generally know or care.
      – Skaperen
      Nov 18 at 6:15


















    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    There many different ways to express code in a shell command line or in a shell script line that can result in a binary being executed. They all just come down to the point of running a shell command. The shell will try to run a file if the command refers to a file. That attempt will succeed if you have permission to execute the file. The file may be a binary executable or a script that refers to its interpreter on the first line (which begins with "#!") or the file may just be plain data like text. If it is executable at that point then it will run or be interpreted. The shell has plenty of ways to express a command. The possibilities are infinite.






    share|improve this answer

























      up vote
      1
      down vote













      There many different ways to express code in a shell command line or in a shell script line that can result in a binary being executed. They all just come down to the point of running a shell command. The shell will try to run a file if the command refers to a file. That attempt will succeed if you have permission to execute the file. The file may be a binary executable or a script that refers to its interpreter on the first line (which begins with "#!") or the file may just be plain data like text. If it is executable at that point then it will run or be interpreted. The shell has plenty of ways to express a command. The possibilities are infinite.






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        There many different ways to express code in a shell command line or in a shell script line that can result in a binary being executed. They all just come down to the point of running a shell command. The shell will try to run a file if the command refers to a file. That attempt will succeed if you have permission to execute the file. The file may be a binary executable or a script that refers to its interpreter on the first line (which begins with "#!") or the file may just be plain data like text. If it is executable at that point then it will run or be interpreted. The shell has plenty of ways to express a command. The possibilities are infinite.






        share|improve this answer












        There many different ways to express code in a shell command line or in a shell script line that can result in a binary being executed. They all just come down to the point of running a shell command. The shell will try to run a file if the command refers to a file. That attempt will succeed if you have permission to execute the file. The file may be a binary executable or a script that refers to its interpreter on the first line (which begins with "#!") or the file may just be plain data like text. If it is executable at that point then it will run or be interpreted. The shell has plenty of ways to express a command. The possibilities are infinite.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 18 at 4:44









        Skaperen

        610512




        610512
























            up vote
            1
            down vote













            Please note that, as Sparhawk pointed out in the comments, the first two examples are doing basically the same (they invoke the program using its path instead of doing a path lookup) and following that logic the ways to execute a given program are virtually infinite.



            Anyway, I'd say there are at least 4 different ways to execute programs[1] from a shell:





            • Shell builtins: some commands, such as echo itself in Bash, are implemented within the shell so the corresponding external utility, if exists, is not invoked.



              $ echo foo
              foo



            • Path lookup: when the shell searches the desired program in each of the directories included in the PATH environment variable.



              $ cat <<< foo
              foo



            • Direct invoking: when the program is invoked using its full/relative path.



              $ /bin/echo foo
              foo




              $ ../../bin/echo foo
              foo



            • Indirect invoking: when the program is invoked by another program (either a builtin or an external one).



              $ eval echo foo
              foo




              $ command echo foo
              foo




              $ sh -c 'echo foo'
              foo






            1. I know you said binaries. I used a more general term because scripts can also be executed from a shell.






            share|improve this answer

















            • 1




              a reference to a file to be executed works the same whether the file is a script or a binary. except for sourcing the shell doesn't generally know or care.
              – Skaperen
              Nov 18 at 6:15















            up vote
            1
            down vote













            Please note that, as Sparhawk pointed out in the comments, the first two examples are doing basically the same (they invoke the program using its path instead of doing a path lookup) and following that logic the ways to execute a given program are virtually infinite.



            Anyway, I'd say there are at least 4 different ways to execute programs[1] from a shell:





            • Shell builtins: some commands, such as echo itself in Bash, are implemented within the shell so the corresponding external utility, if exists, is not invoked.



              $ echo foo
              foo



            • Path lookup: when the shell searches the desired program in each of the directories included in the PATH environment variable.



              $ cat <<< foo
              foo



            • Direct invoking: when the program is invoked using its full/relative path.



              $ /bin/echo foo
              foo




              $ ../../bin/echo foo
              foo



            • Indirect invoking: when the program is invoked by another program (either a builtin or an external one).



              $ eval echo foo
              foo




              $ command echo foo
              foo




              $ sh -c 'echo foo'
              foo






            1. I know you said binaries. I used a more general term because scripts can also be executed from a shell.






            share|improve this answer

















            • 1




              a reference to a file to be executed works the same whether the file is a script or a binary. except for sourcing the shell doesn't generally know or care.
              – Skaperen
              Nov 18 at 6:15













            up vote
            1
            down vote










            up vote
            1
            down vote









            Please note that, as Sparhawk pointed out in the comments, the first two examples are doing basically the same (they invoke the program using its path instead of doing a path lookup) and following that logic the ways to execute a given program are virtually infinite.



            Anyway, I'd say there are at least 4 different ways to execute programs[1] from a shell:





            • Shell builtins: some commands, such as echo itself in Bash, are implemented within the shell so the corresponding external utility, if exists, is not invoked.



              $ echo foo
              foo



            • Path lookup: when the shell searches the desired program in each of the directories included in the PATH environment variable.



              $ cat <<< foo
              foo



            • Direct invoking: when the program is invoked using its full/relative path.



              $ /bin/echo foo
              foo




              $ ../../bin/echo foo
              foo



            • Indirect invoking: when the program is invoked by another program (either a builtin or an external one).



              $ eval echo foo
              foo




              $ command echo foo
              foo




              $ sh -c 'echo foo'
              foo






            1. I know you said binaries. I used a more general term because scripts can also be executed from a shell.






            share|improve this answer












            Please note that, as Sparhawk pointed out in the comments, the first two examples are doing basically the same (they invoke the program using its path instead of doing a path lookup) and following that logic the ways to execute a given program are virtually infinite.



            Anyway, I'd say there are at least 4 different ways to execute programs[1] from a shell:





            • Shell builtins: some commands, such as echo itself in Bash, are implemented within the shell so the corresponding external utility, if exists, is not invoked.



              $ echo foo
              foo



            • Path lookup: when the shell searches the desired program in each of the directories included in the PATH environment variable.



              $ cat <<< foo
              foo



            • Direct invoking: when the program is invoked using its full/relative path.



              $ /bin/echo foo
              foo




              $ ../../bin/echo foo
              foo



            • Indirect invoking: when the program is invoked by another program (either a builtin or an external one).



              $ eval echo foo
              foo




              $ command echo foo
              foo




              $ sh -c 'echo foo'
              foo






            1. I know you said binaries. I used a more general term because scripts can also be executed from a shell.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 18 at 5:51









            nxnev

            2,5482423




            2,5482423








            • 1




              a reference to a file to be executed works the same whether the file is a script or a binary. except for sourcing the shell doesn't generally know or care.
              – Skaperen
              Nov 18 at 6:15














            • 1




              a reference to a file to be executed works the same whether the file is a script or a binary. except for sourcing the shell doesn't generally know or care.
              – Skaperen
              Nov 18 at 6:15








            1




            1




            a reference to a file to be executed works the same whether the file is a script or a binary. except for sourcing the shell doesn't generally know or care.
            – Skaperen
            Nov 18 at 6:15




            a reference to a file to be executed works the same whether the file is a script or a binary. except for sourcing the shell doesn't generally know or care.
            – Skaperen
            Nov 18 at 6:15



            Popular posts from this blog

            Morgemoulin

            Scott Moir

            Souastre