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 或
! 非
有时看脚本的时候不知道具体的判断是什么,可以参考一下。
相关文档:
1、用GCC编译
1.1、创建源文件
(main.c) C 源文件 - main.c
#include
#include “reciprocal.hpp”
int main (int argc, char **argv)
{
int i;
i = atoi (argv[1]);
printf (“The reciprocal of %d is %g\n”, i, reciprocal (i ......
每次都是用到,查一下,写下,这次稍微记录下笔记。
和Thread相关,基本的有3个概念:线程的建立和销毁;线程锁;线程条件
关于建立线程:
ret = pthread_create(&thread_id, NULL, Do_Thread, &Do_Thread_Para);
// 第2参数是thread 属性,一般我不用设置
// 第4个参数是Do_Thread的入口参数,一般我传一个结 ......
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 ......
Telnet服务的配置步骤如下:
一、安装telnet软件包(通常要两个)。
1、 telnet-client (或 telnet),这个软件包提供的是 telnet 客户端程序;
2、是 telnet-server 软件包,这个才是真正的 Telnet server 软件包!
安装之前先检测是否这些软件包已安装,方法如下:
[root@wljs root]#rpm &ndas ......