Shell 学习杂记二

测试
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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值