linux shell脚本之if判断
无论什么编程语言都离不开条件判断。SHELL也不例外。
if list then
do something here
elif list then
do another thing here
else
do something else here
fi
EX1:
#!/bin/sh
SYSTEM=`uname -s` #获取操作系统类型,我本地是linux
if [ $SYSTEM = "Linux" ] ; then #如果是linux的话打印linux字符串
echo "Linux"
elif [ $SYSTEM = "FreeBSD" ] ; then
echo "FreeBSD"
elif [ $SYSTEM = "Solaris" ] ; then
echo "Solaris"
else
echo "What?"
fi #ifend
基本上和其他脚本语言一样。没有太大区别。不过值得注意的是。[]里面的条件判断。
1 字符串判断
str1 = str2 当两个串有相同内容、长度时为真
str1 != str2 当串str1和str2不等时为真
-n str1 当串的长度大于0时为真(串非空)
-z str1 当串的长度为0时为真(空串)
str1 当串str1为非空时为真
2 数字的判断
int1 -eq int2 两数相等为真
int1 -ne int2 两数不等为真
int1 -gt int2 int1大于int2为真
int1 -ge int2 int1大于等于int2为真
int1 -lt int2 int1小于int2为真
int1 -le int2 int1小于等于int2为真
3 文件的判断
-r file 用户可读为真
-w file 用户可写为真
-x file 用户可执行为真
-f file 文件为正规文件为真
-d file 文件为目录为真
-c file 文件为字符特殊文件为真
-b file 文件为块特殊文件为真
-s file 文件大小非0时为真
-t file 当文件描述符(默认为1)指定的设备为终端时为真
3 复杂逻辑判断
-a 与
-o 或
! 非
有时看脚本的时候不知道具体的判断是什么,可以参考一下。
相关文档:
Resources on the site
• Interactive map of GNU/Linux OS and FOSS
• "GNU/Linux is my home" - map of GNU/Linux system
• Interactive map of Linux kernel
• Linux inside
• Linux Technology Reference (single page view)
• Linux kernel diagram
• Li ......
以Debian的方式系列(IN THE DEBIAN WAY):
Linux网络基础
etony C.F.AN etony@tom.com
v0.0.1, 2006-7-23
--------------------------------------------------------------------------------
本文档主要介绍讲述在 Debian系统下有关网络的一些基本信息.
------------------------------------------------------- ......
目录索引
一、与用户管理相关的
配置文件;
1、/etc
/passwd 和/etc/groups
2、超级权
限控制 sudo 的配置文件/etc/sudoers ;
3、添加用
户规则文件 /etc/login.defs 和 /etc/default/useradd
二、添加用户工具和方
法;
1、useradd
工具;
1.1、
useraadd 命令中的 -D运用
1.2、
useradd 添加用户;
......
Telnet服务的配置步骤如下:
一、安装telnet软件包(通常要两个)。
1、 telnet-client (或 telnet),这个软件包提供的是 telnet 客户端程序;
2、是 telnet-server 软件包,这个才是真正的 Telnet server 软件包!
安装之前先检测是否这些软件包已安装,方法如下:
[root@wljs root]#rpm &ndas ......