test expression || [ expression ] 方括号与表达式之间有空格
判断
if [ expression ]; then
command
else
if [ expression ]; then
command
fi
fi
case "$VAR" IN
var1) command1 ;; #;;结束边界
var2) command2 ;;
*) command ;; #default
esac
FOR循环
for variable in (list)
list:
{1..5} 1 2 3 4 5
$() 替换 ``命令 `seq 1 100` $(seq 1 100) or $(seq 1 2 100) step 2
不代列表循环
for VARIABLE # VARIABLE in $@ 可读性更好
类C的循环
for ((expression1; expression2; expression3)) #可以expression1,expression4;
do
echo -n "$i" #不换行
done
无限循环
for ((;1;)) expression2永远为真
WHILE循环
while [[ expression ]]
例
cat file.txt | while read LINE 通过管道
done < file.txt 重定向,差别在于管道会比重定向多两个进程
无限循环
while true || while ((1)) || while :
UNTIL循环
until expression #条件不为真时
无限循环
until ((0)) || until false
SELECT循环
select MENU in (list)
do
command # 此处用break跳出 还可以嵌套 case/esac
done
function
function FUNCTION_NAME() { #function关键字可以省略
command
..
}
导入
. file
source /path/myshell.sh
http://blog.csdn.net/bignoseliu/article/details/5806359