
Language-shell
jichunlai
学着生活
展开
-
shell逻辑运算
[ -a FILE ] 如果 FILE 存在则为真。[ -b FILE ] 如果 FILE 存在且是一个块特殊文件则为真。[ -c FILE ] 如果 FILE 存在且是一个字特殊文件则为真。[ -d FILE ] 如果 FILE 存在且是一个目录则为真。[ -e FILE ] 如果 FILE 存在则为真。[ -f FILE ] 如果 FILE 存在且是一个普通文件则为真。转载 2012-09-06 07:19:13 · 1564 阅读 · 0 评论 -
shell string字符串操作
shell string操作一、判断读取字符串值表达式 含义${var} 变量var的值, 与$var相同 ${var-DEFAULT} 如果var没有被声明, 那么就以$DEFAULT作为其值 *${var:-DEFAULT} 如果var没有被声明, 或者其值为空, 那么就以$DEFAULT作为其值 * ${var=DEFAULT} 如果var没有被声明,原创 2013-04-28 17:13:05 · 1862 阅读 · 0 评论 -
shell 字符串操作
shell 字符串操作(长度,查找,替换)在做shell批处理程序时候,经常会涉及到字符串相关操作。有很多命令语句,如:awk,sed都可以做字符串各种操作。 其实shell内置一系列操作符号,可以达到类似效果,大家知道,使用内部操作符会省略启动外部程序等时间,因此速度会非常的快。一、判断读取字符串值表达式含义${var}变量var的值, 与$var相同${va原创 2012-09-04 20:41:34 · 1479 阅读 · 0 评论 -
shell语法case
#!/bin/bash## script to test case statement#action="update"case $action in"update")echo "update the db";;"select")echo "select from db";;"delete")echo "delete from db";原创 2013-05-05 20:00:56 · 1572 阅读 · 0 评论 -
shell语法if else elif
#!/bin/sh## test the if .. elif .. else#if [ $1 -gt 0 ] ; thenecho "$1 is positive"elif [ $1 -lt 0 ] ; thenecho "$1 is negative"elif [ $1 -eq 0 ] ; thenecho "$1 is zero"elseecho原创 2013-05-05 20:05:04 · 1642 阅读 · 0 评论 -
shell语法for
#!/bin/bashfor (( i = 0; i doecho "welcome $i times"done#!/bin/sh## test for #for i in 1 2 3 4 5 doecho "welcome $i times"done原创 2013-05-05 20:05:41 · 1473 阅读 · 0 评论 -
shell语法while
#!/bin/sh# calculate the sum from 1 to n# validate the varibles numberif [ $# -ne 2 ] ; thenecho "usage : sum.sh start end"exitfistart=$1end=$2while [ $start -lt $end ]原创 2013-05-05 20:08:13 · 1594 阅读 · 0 评论 -
shell特殊的环境变量 特殊字符 文件测试参数
特殊的环境变量$*所有命令行参数的值$#命令行参数的总数$$当前进程的进程ID(PID)$?最后执行的一条命令的退出状态,返回值为0则成功,非0则失败$!在后台运行的最后一个进程的进程IDshell中的特殊字符特殊字符有着重要的作用。包括:通配符引号 命令执行顺序操作符注释符、反斜线及后台操作符 文件测试参数功能原创 2013-05-05 19:57:42 · 1926 阅读 · 0 评论 -
shell语法function
#!/bin/bashfunction demo(){echo "all function args : $*"echo "the first arg : $1"echo "the second arg : $2"echo "the third arg : $3"}# call the functiondemo -f foo bar原创 2013-05-05 20:07:23 · 1582 阅读 · 0 评论