shell_debug

shell

shell编程在实际工作中经常用到,但是如何高效的进行debug呢?比较简单的用法:

sh -x test.sh
output:
+ parament=test
+ echo test
test

具体的debug调试可参考:
https://blog.csdn.net/Jerry_1126/article/details/52096886;
https://www.ibm.com/developerworks/cn/linux/l-cn-shell-debug/index.html

set -e: 若指令传回值不等于0,则立即退出shell [shell错误不会直接退出,还会继续执行,需要设置set -e]

http://www.ruanyifeng.com/blog/2017/11/bash-set.html

shell批量文件重命名

n=0; for f in xxx_*; do mv $f xxx_$n.txt; ((n+=1)); done

seq和while readline配合

seq 3 1 5 | while read line;do         // 抽象 command | while read line;do
    echo $line
done
读取文件的两种方式
方式1:
cat file | while read line;do
    echo $line
done
方式2:
while read line;do
    echo $line
done < file

shell中等待

  • sleep 暂停
  • wait 等待前面的进程执行完后再执行
posted @ 2019-11-10 18:58  baishengguan  阅读(211)  评论(0编辑  收藏  举报