What happens when this command is executed?
Error: Nothing happens when i execute the command in the terminal.
If you execute the command in your question, you should get an error message:
$ PATH =$PATH:`pwd` bash: PATH: command not found
If the space is a typo, and you actually run this:
Then that will add the current directory (
pwd is a command that prints the path of the current directory, and
`pwd` will be replaced with the output of
pwd) to the
PATH variable for the duration of your current shell session (util you close the terminal). To illustrate:
$ pwd /home/terdon/foo ## I am in /home/terdon/foo $ echo $PATH ## the current PATH /home/terdon/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games $ PATH=$PATH:`pwd` $ echo $PATH /home/terdon/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/terdon/foo
Note how the current directory,
/home/terdon/foo has been added to the end of the
As far as your original command goes, terdon's answer already covers very well what is happening and what should happen. Let's analyze that slightly in more detail.
What you're trying to do is variable assignment, which should take form of:
However, because of the space this is treated as a command
PATH with command line argument consisting of a
= then contents of variable
$PATH and command-substitution of
pwd, all joined in to same string:
Of course, there is no such command as
PATH, hence you will get an error.
Shell treats simple commands and their arguments as list of one or more space-separated tokens (with perhaps optional variable assignment before that). In other words, the form should be:
[VAR=value] word [arg1 [arg2 [arg3] ]...]
Of course, this is not what is desired in this case.
So what should have been done is this:
Here we have proper variable assignment, where in accordance with the expansion order,
bash shell would first perform variable expansion, i.e. replace
$PATH with whatever you have in that variable currently, then perform command-substitution where it runs
pwd and replaces it with output of
pwd. In the end, all that gets assigned back to
A few key observations:
$PATHvariable, but usually you should to avoid undesirable behavior. See When is Double Quoting Necessary
PATHvariable is used by shell to find commands, and the order of directories on that list sets the precedence to where commands would be searched. So for example, when you execute a command the shell would first check whether the command is built-in, if it's not then it would look through all directories on the
PATH=$PATH:$(pwd)would make shell traverse everything else, and only then get to the directory that was given by
pwd. By contrast,
PATH=$(pwd):$PATHwould start the search from the directory returned by
pwdfirst. So order of the assignment matters.