在/etc/profile
中有PATH变量,
PATH=$PATH:/usr/local/php-5.5/bin
与 export PATH=$PATH:/usr/local/php-5.5/bin
有什么区别?
========
source命令是在当前的shell中执行shell脚本,而不是在子shell当中,是吗?
PHP中文网2017-04-17 11:31:04
First of all, export
is part of the syntax of POSIX-compatible shells and has no necessary relationship with Linux. It is not a command, but a modifier (similar to declarations like integer
, local
in bash / zsh).
Secondly, the meaning of export
. export var
means that the variable var
will be inherited by the child process of the shell as the environment variable . By default, variables in POSIX-compatible shells are only used by the shell itself, not environment variables, and will not be inherited by child processes. export var=xxx
is the shorthand syntax supported by bash and others. var=xxx cmd
is the syntax used to set the var
environment variable only for a single command.
Finally, about PATH
environment variables. It's an environment variable, meaning it's been export
ed. PATH
, HOME
These are environment variables themselves and do not need to be explicitly export
. So there is no difference.
Regarding source
or .
, yes. It means reading and executing the script from the specified file (the path will be searched using the PATH
variable, just like the executable file), which is similar to what you manually enter at the shell prompt. The term source isn't just used in shells either.
黄舟2017-04-17 11:31:04
There is a PATH variable in /etc/profile. What is the difference between PATH=$PATH:/usr/local/php-5.5/bin and export PATH=$PATH:/usr/local/php-5.5/bin?
I think there is no difference. In fact, your /etc/profile will execute source /etc/profile when the system starts, but you will not run it yourself.