shell脚本编程<二>:if-then,case结构化命令
2015-12-31 22:34
851 查看
使用if-then语句
格式如下if commands then commands fi 或 if commands; then command fi
举个栗子
#!/bin/bash #testing a bad command if asjfkd then echo "it didn't work" fi
再看个栗子
#!/bin/bash #testing multiple commands in the then section testuser=rich if grep $testuser /etc/passwd then echo the bash files for user $testuser are: ls -a /home/$testuser/.b* fi
if-then-else语句
格式如下:if commands then commands else commands fi
嵌套if语句
格式如下if command1 then commands elif command2 then more commands fi
case命令
先看case命令的格式,如下case varialbe in pattern1 | pattern2) command1;; pattern3) command2;; *) default commands;; esac
看一个栗子
#!/bin/bash case $USER in rich | barbara) echo "welcome, $USER" echo "enjoy";; testing) echo "special testing account";; *) echo "sorry, you're not allowed here";; esac
相关文章推荐
- shell修改配置文件
- shell脚本编程<一>:变量及脚本中数学计算
- bash反弹shell
- 基于CentOS的MySQL学习补充五--使用Shell备份(mysqldump)MySQL数据库
- mysqldump全备的shell脚本分享
- 一个备份MySQL数据库的简单Shell脚本
- linux shell 脚本30分钟教程
- ShellExcuteA
- linux创建新用户后shell无法自动补全命令
- 程序中执行shell命令行,获取system目录读写权限
- linux shell 输入密码不显示
- linuxSHELL学习之数字比较、字符串比较
- linux shell 正则表达式(BREs,EREs,PREs)差异比较(转)
- shell数组建立和基本使用方法
- bash脚本编程之一变量、变量类型等
- shell中的变量的备忘
- shell编程之for循环-写指定数量的单词到文件
- git bash使用指南(markdown版本)
- shell之declare 声明变量类型
- python shell 根据ip 获取 hostname || 根据hostname 获取 ip