bash小结
2018-07-19 本文已影响0人
alex_zn
Shell脚本编程
shell 标识第一行
#!/bin/sh
变量
v1="macos"
echo $v1
v2="windows"
echo $v2
字符串
单引号字符串的限制:
- 单引号里的任何字符都会原样输出,单引号字符串中的变量是无效的
- 单引号字串中不能出现单引号(对单引号使用转义符后也不行)
str='this is a string'
双引号
name="zhanshan"
str="hello,$name"
拼接字符串
fullName="$name,$str"
条件变量
# if
if condition
then
command1
command2
...
commandN
fi
#if else
if confition
then
command
eles
command
fi
#for循环
for item in item1 item2...itemN
do
command
done
#自增
for(c1;c2;c3)
do
commeand
done
#循环
while condition
do
command
done
数组
arr1=(A,B,"C",$val)
函数
testFunc1() {
echo "fun1"
}
testFunc2() {
echo "第一个参数$1"
echo "第二个参数$2"
}