I knew that there is a variable PWD which is changed when I type the command cd. But when I try to change it manually the current directory isn't changed. How to manipulate PWD directly?
Assignments to this variable may be ignored.
Assignments are not special in bash, dash, ash, zsh or ksh, and the value will simply be overwritten next time the shell changes directory.
While other shells might support such a variable as well, the $PWD variable is generally specific to the bash shell.
The bash manual says:
PWD
The current working directory as set by the cd builtin.
Meaning it will be set when you use the cd builtin to change a directory but bash will not change the current directory when you set $PWD.
At least on my Mac and Linux machines running bash you can just overwrite the variable, so running PWD=/ will change your current directory (in the prompt) to /.
The variable PWD in bash is in control of the shell's working directory (again only the prompt) and you will see that the directory after the PWD= command has been changed but the pwd command isn't impacted by the change.
<0>xxxx@dhcp89-089-034:~$ PWD=/
<0>xxxx@dhcp89-089-034:/$ pwd
/Users/xxxx
Now the environment variable PWD is a bash prompt thing and is not the real working directory, nor is modifying it a useful thing to do unless you actually use the 'cd' command.