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 或
! 非
有时看脚本的时候不知道具体的判断是什么,可以参考一下。
相关文档:
利用
下载的这段代码,成功实现了守护进程,原来守护进程是很简单的事情。
在main函数中执行
init_daemon();//初始化为Daemon
就可以把进程变成守护进程
#include
#include
#include
#include
#include
void
init_daemon(void
)
{
int
pid;
int
i;
if
(pid=fork()) ......
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 ......
linux
下 mysql
用户的管理
文章分类:数据库
关键字: linux
mysql
用户管理
自从上在redhat Enterprise 5 中安装了MySQL
,这次来实践操作一下MySQL
用户的管理;
一、root用户密码的维护:
由于安装MySQL
完后,MySQL
会自动提供一个不带 ......
文章来源:http://blog.chinaunix.net/u1/51562/showart_405963.html
http://ericxiao.cublog.cn/对内核源码分析的比较详细,感谢文章作者无私奉献
本文欢迎转载!
转载请注明出处:http://ericxiao.cublog.cn/
------------------------------------------
<<prison break>>第三季的第五集,终于在翘首企盼 ......
Programming your application or library based on Qt has always had the promise that you can deploy your application on many different platforms. Development of those applications can, likewise, happen on many different platforms. QtCreator runs on Windows, Mac & Linux among others.
Qt很简单,易 ......