Running this command (where a.out
is a valid C executable):
. a.out
...results in this error:
bash: .: a.out: cannot execute binary file
However, running the following command:
./a.out
...successfully executes the C binary executable.
Clearly, there are 2 types of executions happening here, what's different?
The difference is that word splitting and glob expansion are not performed for variables inside [[...]] so quoting the variables is not so crucial.
Example of command substitution using $() in Linux: Again, $() is a command substitution which means that it “reassigns the output of a command or even multiple commands; it literally plugs the command output into another context” (Source).
In short (in bash): Yes both = and == are the same (inside test constructs).
So, what we learned is, the “>” is the output redirection operator used for overwriting files that already exist in the directory. While, the “>>” is an output operator as well, but, it appends the data of an existing file.
The shell uses spaces to separate the command to run and its parameters.
In the first example, the command to run is .
with a parameter of a.out
. The .
command is a shell shortcut for source
, which takes the name of a file containing shell commands as its first parameter and runs those commands in the current shell. This command fails because a.out
is a binary file, not a shell script.
In the second example, the command to run is ./a.out
, which means run the file a.out
residing in the current directory.
./program
runs a file named program
located in your current working directory (./
) (in a new shell for a shell script)..
is the same as source
, which runs a shell script in your current shell. Unlike ./program
, it can't be used to run binaries! As an example, you could use this command to run your .bashrc
shell script, because you want this script to modify your current shell.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With