env
名字
env - 在一个改变的环境运行一个程序
梗概
env [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]
描述
Set each NAME to VALUE in the environment and run COMMAND.
- -i, --ignore-environment start with an empty environment
- -0, --null end each output line with 0 byte rather than newline(输出的变量键值对不换行)
- -u --unset=NAME remove variable from the environment
- --help display this help and exit
- --version output version information and exit
主要的环境变量
- HOME 用户的主文件夹
- SHELL 目前这个环境使用的shell是哪个程序?Linux默认使用/bin/bash的
- HISTSIZE 这个命令与"历史有关", 即是我们曾经执行过的命令可以被系统记录下来,而记录的"条数"则是由这个值来设置的
- MAIL 我们使用mail这个命令在收信时系统会去读取的邮件箱文件(mailbook)
- PATH 就是执行文件查找的路径目录与目录中间以冒号(:)分隔,由于文件的查找是依据由PATH的变量内的目录来查询,所以目录的顺序也是重要的.
疑: 目录的查找优先级顺序
答:目录排在前面的优选级高,也就是一个命令如果在前面的目录中找到,就不会在后的目录中继续查找
- LANG 这是语系数据
- RANDOM 这个是"随机数"
$ echo $RANDOM
24965
$ echo $RANDOM
30763
- PS1 (提示符的设置) 当我们每次按下[Enter]按键去执行某个命令后,最后要再次出现提示符时,就会主动去读取这个变量值了。上面PS1内显示的是一些特殊符号,这些特殊符号可以显示不同的信息,每个distrbutions的bash默认的PS1变量内容可能有些区别,你可以用 man bash查询一下PS1的相关说明,以理解下面的一些符号的意义。
PROMPTING
- \a an ASCII bell character(07)
- \d the date in "Weekday Month Date" format(e.g., "Tue May 26")
- \D{format} the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required
- \e an ASCII escape character(033)
- \h the hostname up to the first '.'
- \H the hostname
- \j the number of jobs currently managed by the shell
- \l the basename of the shell's terminal device name
- \n newline
- \r carriage return
- \s the name of the shell, the basename of $0(the portion following the final slash)
- \t the current time in 24-hour HH:MM:SS format
- \T the current time in 12-hour HH:MM:SS format
- \@ the current time in 12-hour am/pm format
- \A the current time in 24-hour HH:MM format
- \u the username of the current user
- \v the version of bash(e.g., 2.00)
- \V the release of bash, version + patch level (e.g., 2.00.0)
- \w the current working directory, with $HOME abbreviated with a tilde(uses the value of the PROMPT_DIRTRIM variable)
- \W the basename of the current working directory, with $HOME abbreviated with a tiled
- ! the history number of this command
- $ if the effective UID is 0, a #, otherwise a $
- \nnn the character corresponding to the octal number nnn
- \ a backslash
- \[ begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
- \] end a sequence of non-printing characters
The command number and the history number are usually different: the history number of a command is its position in the history list, which may include commands restored from the history file(see HISTORY below), while the command number is the position in the sequence of commands executed during the current shell session. After the string is decoded, it is expanded via parameter expansion, command substitution, arithmetic expansion, and quote removal, subject to the value of the promptvars shell option(see the description of the shopt command under SHELL BUILTIN COMMANDS below).