您好,欢迎来到爱够旅游网。
搜索
您的当前位置:首页Shell_shell脚本基础

Shell_shell脚本基础

来源:爱够旅游网

1.echo:

echo -e,显示转义符号;

echo ${var},显示变量值;

echo -e "no new line\c",\c不换行;

echo '${var}',原样输出;

echo `date`,输出命令结果;

2.数组(index从0开始):

array=($a $b $c)

echo ${array[0]},单个元素

${#array[0]},单个元素长度

${array[@]},全部元素

${#array[@]},${#array[*]}全部元素长度

3.注释:

#单行

多行

:<<EOF

<<EOF

4.字符串(index从0开始):

${#str},字符串长度

${#str:1:4},从1开始4个

expr index ${str} ${substr},查找字符串,输出开始位置,最小为1;没发现是0

5.变量:

只读,readonly vari

删除,unset vari

6.包含其他shell:

. shell脚本全路径;或者,source shell脚本全路径

7.定向输出:

0:stdin

1:stdout

2:stderr

/dev/null 垃圾堆

2 &> /dev/null 将0和2合并,输出到垃圾堆。

>重定向符号;

&合并符号;

8.函数:

函数需要定义在使用之前。

函数不带返回值的话,将最后一条command结果作为返回值;函数返回值,在调用该函数后通过 $? 来获得。

函数参数,${10},两位的需要加{};$*:参数字符串; $@参数列表;$#参数个数。

9.流程控制:

不能有空的if或者else语句;

if:if [ xx ]; then xx elif [ xx ]; then xx else xx fi;

for: for a in b do xx done;

while: while [ xx ] do done;

case: case xx in A) XX;; B) XX;; *) XX;; esac

break: 跳出所有循环,n层;

continue:跳出内层循环,外层不跳出;

until: until [ xx ] do xx done;条件为真时跳出;

 

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- igbc.cn 版权所有 湘ICP备2023023988号-5

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务