shell - linux 下export 命令有什么用
巴扎黑
巴扎黑 2017-04-17 11:29:04
0
2
690

/etc/profile 中有PATH变量, PATH=$PATH:/usr/local/php-5.5/binexport PATH=$PATH:/usr/local/php-5.5/bin 有什么区别?

========
source命令是在当前的shell中执行shell脚本,而不是在子shell当中,是吗?

巴扎黑
巴扎黑

reply all(2)
Ty80

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 exported. 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.

黄舟

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template