shell学习第三章:shell环境变量

参考链接:https://bash.cyberciti.biz/guide/Main_Page

1、变量可以用来储存数据,或者配置操作。有两种类型的变量:系统变量、用户自定义变量

系统变量由bash shell建立维护,输入下面指令查看所有的系统变量

set
或者
env

或者

printenv
2、下面的这些变量由shell设置,也就是是系统变量
System VariableMeaningTo View Variable Value Type
BASH_VERSIONHolds the version of this instance of bash.echo $BASH_VERSION
HOSTNAMEThe name of the your computer.echo $HOSTNAME
CDPATHThe search path for the cd command.echo $CDPATH
HISTFILEThe name of the file in which command history is saved.echo $HISTFILE
HISTFILESIZEThe maximum number of lines contained in the history file.echo $HISTFILESIZE
HISTSIZEThe number of commands to remember in the command history. The default value is 500.echo $HISTSIZE
HOMEThe home directory of the current user.echo $HOME
IFSThe Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read builtin command. The default value is <space><tab><newline>.echo $IFS
LANGUsed to determine the locale category for any category not specifically selected with a variable starting with LC_.echo $LANG
PATHThe search path for commands. It is a colon-separated list of directories in which the shell looks for commands.echo $PATH
PS1Your prompt settings.echo $PS1
TMOUTThe default timeout for the read builtin command. Also in an interactive shell, the value is interpreted as the number of seconds to wait for input after issuing the command. If not input provided it will logout user.echo $TMOUT
TERMYour login terminal type.echo $TERM
export TERM=vt100
SHELLSet path to login shell.echo $SHELL
DISPLAYSet X display nameecho $DISPLAY
export DISPLAY=:0.1
EDITORSet name of default text editor.export EDITOR=/usr/bin/vim

3、如何获取一个变量的值,并打印

echo "$PATH"

4、printf命令和echo命令差不多

printf "$VARIABLE_NAME\n"
printf "String %s" $VARIABLE_NAME
printf "Signed Decimal Number %d" $VARIABLE_NAME
printf "Floating Point Number %f" $VARIABLE_NAME

5、创建一个变量并赋值,在脚本中非常常见,采用下面的指令

varName=someValue

然后通过echo或者printf打印出来变量的值

echo "$varName"
echo "${varName}"

pritnf "${varName}"
printf "%s\n"${varName}

去变量的值的时候,尽量带上{},这样可以尽可能地避免二义性。

看到default shell variables value这块了。

https://bash.cyberciti.biz/guide/Default_shell_variables_value


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值