hzmct@U-64:~$ help aliasalias: alias [-p] [name[=value] ... ]
Define or display aliases.
Without arguments, `alias' prints the list of aliases in the reusable
form `alias NAME=VALUE' on standard output.
Otherwise, an aliasis defined for each NAME whose VALUE is given.
A trailing space in VALUE causes the next word to be checked foralias substitution when the aliasis expanded.
Options:
-p Print all defined aliases in a reusable format
Exit Status:
alias returns true unless a NAME is supplied for which no alias has been
defined.
hzmct@U-64:~$ alias -p
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'alias egrep='egrep--color=auto'alias fgrep='fgrep--color=auto'alias grep='grep--color=auto'alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls--color=auto'
hzmct@U-64:~$ alias chen="pwd"
hzmct@U-64:~$ chen
/home/hzmct
hzmct@U-64:/study/linuxtest/day03$ help declare
-f restrict action or display to function names and definitions 只显示函数名
-g create global variables when used in a shell function; otherwise ignored
-p display the attributes and value of each NAME
Options which set attributes:
-a to make NAMEs indexed arrays (if supported)
-A to make NAMEs associative arrays (if supported)
-i to make NAMEs have the `integer' attribute
-l to convert NAMEs to lower case on assignment
-n make NAME a reference to the variable named by its value
-r to make NAMEs readonly(设置变量只读)
-t to make NAMEs have the `trace' attribute
-u to convert NAMEs to upper case on assignment
-x to make NAMEs export(声明环境变量)
--------------------------示例----------------------------
//声明一个整型变量
$ declare -i num=12
//查看整型变量
$ declare -p num
declare -i num="12"
//声明数组变量
$ arr[0]=x
$ arr[1]=y
$ declare -a arr[2]=z
查看数组
$ echo ${arr}
x
$ echo ${arr[2]}
z
$ echo ${arr[8]}
//声明环境变量
$ declare -x t=123
//声明变量只读属性
$ declare -r t=123
$ t=55
-bash:t: readonly variable
//查看所有变量属性
$ declare -p
//查看指定变量属性
$ export AA="12345"
$ declare -p AA
declare -x AA="12345"
export
export: export [-fn] [name[=value] ...] or export -p Options:
-f refer toshell functions
-n remove the export property fromeach NAME
-p display a list of all exported variables and functions
An argument of `--' disables further option processing.
export 用户创建传给shell的变量,即:创建环境变量
-- 表明选项结束,所有后续参数都是实参
-f 表明在“名-值”对中的名字是函数名。
-n 把全局变量转换成局部变量。换句话说,命令的变量不在传给shell
-p 显示全局变量列表
//使用export将局部变量转化为全局变量
//先定义一个局部变量
hzmct@U-64:/study/linuxtest/day03$ var2="i am global now"
//声明为全局变量
hzmct@U-64:/study/linuxtest/day03$ export var2
//启动子shell
hzmct@U-64:/study/linuxtest/day03$ sh
$ echo $var2
i am global now
//退出子shell
$ exit
hzmct@U-64:/study/linuxtest/day03$ echo $var2
i am global now
//将全局变量转化为局部变量
hzmct@U-64:/study/linuxtest/day03$ export -n var2
hzmct@U-64:/study/linuxtest/day03$ sh
$ echo $var2
$ exit
hzmct@U-64:/study/linuxtest/day03$
readonly
readonly 用于显示或者设置只读变量
-- 表明选项结束
-f 创建只读变量
set
set 使用set命令显示所有本地定义的shell变量。
设置或者重设各种shell
set -a