shell变量和运算符是什么样的?
shell变量和运算符是什么样的?
-本地变量 -影响变量的命令 -环境变量 -引号 -变量替换 -运算符 -位置变量 -表达式替换 -标准shell变量 -运算符的优先级 -特殊变量 -变量: -什么是shell变量? -本地变量 -环境变量 -变量替换(显示变量) -位置变量 -标准变量 -特殊变量 -影响 变量的命令 -本地变量: -本地变量在用户现在的shell生命期的脚本中使用 -variable-name=value -set显示本地所有的变量 -readonly variable-name #LOCALTEST="test" #echo ${LOCALTEST} test #echo $LOCALTEST test #set 通过set查看变量 #exit 退出后查看一下还是否存在LOCALTEST变量 #readonly LOCALTEST #LOCALTEST="test" #readonly 查看当前shell有那些只读变量 #readonly -p -环境变量 -环境变量用于所有用户进程(经常称为子进程)。
登录进程称为父进程。shell中执行的用户进程均称为子进程。不像本地变量(只用于现在的shell)环境变量可用于所有子进程,这包括编辑器,脚本和应用。 -$HOME/。bash_profile(/etc/profile) -export -env #cat /etc/profile #export Antiy="xi'an" #env 然后查找变量Antiy #export 也可以查看 #readonly Antiy 设置为只读 #export Antiy="xidian" 看是否可以修改,会提示不可以,因为只读了。
-变量替换: -用变量的值替换它的名字。 -echo -在变量名前加$,使用echo命令可以显示单个变量取值。
#testvar="this is a test" #echo $testvar this is a test #echo ${testvar} 变量替换-续 ${Variable name} 显示实际值到variable name ${Variable name:+value} 如果设置了variable name,则显示其值value,否则,为空! ${Variable name:?value} 如果未设置variable name,显示用户定义错误信息value! ${Variable name:-value} 如果未设置variable name, 则显示其值value ${Variable name:=value} 如果未设置variable name,设置其值,并显示 #echo ${testvar:+"xidian"} xidian #echo ${testvar1:+"xidian"} 为空 #echo ${testvar1:?"no defined"} bash:testvar1:no defined #echo ${testvar1:-"xidian"} #echo ${testvar:-"xidian"} xidian #echo ${testvar:="xidian"} this is a test #echo ${testvar2:="xidain"} xidian #echo $testvar2 xidian -变量清除: #echo $testvar this is a test #unset testvar #echo $testvar 空 #echo $testvar2 #readonly testvar2 #unset testvar2。
答:按顺序执行详情>>