1 数组的使用
#!/bin/bash name="zhangdiqing" echo ${#name} echo ${name:1:4} echo $name $name name="zhangdiqing" echo `expr index "$string" is` array_name=(zhang,wang,li,zhao) array=( zhang wang li zhao) #the index no bondary array_name[0]=qing #read the array echo ${array_name[0]} #read all echo ${array_name[@]} #gain the len len=${#array_name[@]} len=${#array_name[*]}
2. 运算符的使用
#!/bin/bash
val=`expr 2 + 2`
echo $val
a=10
b=12
if [ $a -eq $b ]
then
echo "a==b"
fi
if [ $a -ne $b ]
then
echo "a!=b"
fi
if[ $a -gt $b ]
# a>b
then
echo "a>b"
fi
if [ $a -lt $b ]
#a<b
then
echo "a<b"
fi
if [ $a -ge $b ]
# a>=b
then
echo "a>=b"
fi
if [ $a -le $b ] #a<=b
then
echo "a<=b"
fi
if [ ! false ]
then
echo "!false"
fi
if [ false -o true ] # bool or
echo "false -o true"
fi
# [ false -a true ] #bool and
#
#
#
# [0&&7] #logical and
# [0||1] #logical or
3. 参数的使用
#!/bin/bash
echo "$0"
echo "$1"
echo "$2"
echo "$3"
#argu numbers
echo $#
#the current pid
echo $$
#后台运行的最后一个进程的PID
echo $!
#最后一条命令的执行结果,0表示没有错误
echo $?
echo $*
echo $@
#显示shell使用的当前选项
echo $-
4.函数
[ function ] funname [()]
{
action;
[returnint;]} 文件包含:
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|