Shell 学习杂记二
2016-12-29 08:51
260 查看
测试
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
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
相关文章推荐
- Linux Shell sort排序常用命令
- 极点五笔/xshell远程/桌面or命令启动/配制打印机/
- 小白的centos6.5笔记--Shell基础
- Linux CentOS下shell显示-bash-4.1$不显示用户名路径的解决方法
- shell 脚本手动制作nginx电子书
- shell脚本的第一行
- Bash on Windows 搭建ESP32开发环境
- Linux中profile、bashrc、bash_profile之间的区别和联系
- ubuntu 16.04 gedit 配置
- 【鸟哥Linux】认识与学习BASH
- shell 的echo
- shell脚本产生指定时间段内的每月开始时间和结束时间
- shell脚本产生指定时间内的每天日期
- [Shell] swoole_timer_tick 与 crontab 实现定时任务和监控
- Linux 基础学习 Bash(RHEL)
- 安装使用SharePoint Online Management Shell的时候出现的问题
- 关于win7虚拟机Ubuntu用Xshell连接
- 向shell脚本中传入参数
- 用shell 脚本创建lfw的正负样本对
- shell 二维数组