Shell编程--shell基础二

1、declare声明变量类型

[root@localhost ~]# declare [+/-][选项] 变量名
选项:
-:    给变量设定类型属性
+:    取消变量的类型属性
-i:   将变量声明为整数型(integer)
-x:    将变量声明为环境变量
-p:   显示指定变量的被声明的类型

2、数值运算--方法1
 

[root@localhost ~]# aa=11
[root@localhost ~]# bb=22
#给变量aa和bb赋值
[root@localhost ~]# declare -i cc=$aa+$bb

方法2:使用expr或let数值运算工具

[root@localhost ~]# aa=11
[root@localhost ~]# bb=22
#给变量aa和变量bb赋值
[root@localhost ~]# dd=$(expr $aa + $bb)
#dd的值是aa和bb的和。注意"+"号左右两侧必须有空格

方法3:"$((运算式))" 或 $[运算式]

[root@localhost ~]# aa=11
[root@localhost ~]# bb=22
[root@localhost ~]# ff=$(($aa+$bb))
[root@localhost ~]# ff=$[$aa+$bb]

#####################################################################################################
环境变量配置文件

配置文件简介

1、source命令或者“.”

[root@localhost ~]# source 配置文件简介
或
[root@localhost ~]# . 配置文件

2、环境变量配置文件简介(etc目录下是全局的配置文件)

/etc/profile
/etc/profile.d/*.sh
~/.bash_profile
~/.bashrc
/etc/bashrc

其他配置文件和登陆信息
1、注销时生效的环境变量配置文件
~/.bash_logout
~/.bash_history

3、shell登陆信息

本地终端登陆信息: /etc/issue       远程终端登陆信息: /etc/issue.net

扫描二维码关注公众号,回复: 3007127 查看本文章
\d 显示当前系统日期
\s 显示操作系统名称
\l 显示登陆的终端号。
\m 显示硬件体系结构,如i386、i686
\n 显示主机名
\o 显示域名
\r 显示内核版本
\t 显示当前系统时间
\u 显示当前登陆用户的序列号

远程终端登陆信息: /etc/issue.net
   转义符在/etc/issue.net文件中不能使用
   是否显示此登陆信息,由ssh的配置文件/etc/ssh/sshd_config决定,加入
   "Banner /etc/issue.net" 行才能显示()

4、本地和远程登陆都生效  /etc/motd


/etc/issue本地登陆生效,/etc/issue.net远程登陆生效
/etc/motd本地和远程都生效但是是登陆之后的
 

猜你喜欢

转载自blog.csdn.net/qq_28710983/article/details/81676638