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
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
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.
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.
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 '18 at 03:56