以下的知识来源于网络,如有侵权,请联系我删除哈
内容介绍:
1、if 语句
2、if else 语句
3、if elif else 语句
4、case in 语句
5、for in 语句
6、while 语句
7、函数
详细内容介绍:
1、if 语句
#第一种定义方式:
if condition
then
statement
if
#第二种方式:
if condition ; then
statement
if
第一种方式:
第二种方式:
2、if else 语句
if condition
then
statement
else
statement
if
3、if elif else 语句 (助记:有if就有then)
if condition
then
statement
elif condition
then
statement
else
statement
if
4、case in 语句(跟c语言类似哈)
case expression in
pattern1)
statement1
;;
pattern2)
statement2
;;
..... #省略了很多语句哈
*)
statement
;;
5、for in 语句
#语法格式:
for variable in value_list
do
statement
done
#其中value_list的取值可以是以下几种情况哈:
# 1、直接给出具体的值
# 2、给出一个取值范围
# 3、使用命令的执行结果
# 4、使用shell 通配符
# 5、使用特殊变量($*、$@)
第1种情况:value_list为直接给出具体的值:
第2种情况:value_list为给出一个取值范围:
第3种情况:value_list为给出一个取值范围:
空格作为分隔符号哈
第4种情况:value_list为使用shell通配符:
第5种情况:value_list为使用特殊变量:
貌似上面的打印没什么区别哈,他们的区别需要加上双引号,比如"
@
"
、
"
@" 、"
@"、"*"
在for循环中
∗
和
*和
∗和@的区别(在加了双引号之后哈):
6、while 语句
7、函数
# 语法格式:
function name(){
statement
[return value]
}
到此关于shell的基础语法讲完了,后续会试着分析Ubuntu中的shell脚本来强化记忆和熟悉运用。
敬请期待,待续。。。。