微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

shell脚本


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;]}
文件包含:
source filename

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐