• Shell Script注释和debug


    一、ShellScript注释

    # 代表不解释不执行

    –语法:#-比如:# 这是一行注释

    二、hellScriptDebug

    #bash [-nvx] scripts.sh

    –选项与参数:

    -n :不要运行script,仅查询语法的问题;

    -v :再运行sccript前,先将整个scripts 的内容输出到屏幕上;

    -x :将执行到的script 内容显示到屏幕上,这是很有用的参数!

    •创建一个脚本文件sh01.sh:

    #!/bin/bash

    echo "hello

    mkdir./test/adirs./test/bdirs

    ls-l ./

    •以上内容中,我们制造一个bug:

    –echo "hello 这里我们忽略最后的双引号

    •#bash [-nvx] scripts.sh

    –选项与参数:

    -n :不要运行script,仅查询语法的问题;

    1. [root@hadoop scripts]# more hello.sh
    2. #!bin/bash
    3. echo "hello,world"
    4. [root@hadoop scripts]# hello.sh
    5. -bash: hello.sh: command not found
    6. [root@hadoop scripts]# bash hello.sh
    7. hello,world

    三、Shell 扩展

    使用选项-vx做进一步测试

    •创建一个脚本文件test.sh:

    #!/bin/bash

    mkdir-p ./test/{a,b,c}dirs

    scp/etc/{profile,init.d/network} ./test/

    echo $PATH

    #bash -vx test.sh

    –-v选项使得脚本中的命令显示出来

    –-x选项显示shell对脚本命令的解释结果,即shell解释器扩展命令字符串的结果

    •扩展知识:

    –shell扩展:花括号扩展

    –shell扩展:变量参数扩展

    •通过使用tree命令显示当前目录的属性结构

    •*通过yum install tree -y来安装该命令

    •shell扩展:花括号扩展

    –mkdir -p ./test/{a,b,c}dirs

    –+ mkdir -p ./test/adirs ./test/bdirs ./test/cdirs

    –scp /etc/{profile,init.d/network} ./test/

    –+ scp /etc/profile /etc/init.d/network ./test/

    •花括号扩展:

    –不能出现在引用中

    –花括号前后的前缀是可选的

    –最少出现一个逗号

    •shell扩展:变量参数扩展

    –echo $PATH

    –+ echo /usr/lib64/qt-3.3/bin:/u。。。。。。

    •符号$对使用的bash而言是获取参数变量值的特殊标识

    –完整写法:${parameter}

  • 相关阅读:
    15 DOM 扩展
    javaweb基础:tomcat的安装,以及目录结构
    元宇宙的核心技术之我见
    Flutter高仿微信-第42篇-创建群
    Endnote 中批量导出PDF
    后台开发核心技术与应用实践看书笔记(一):C++编程常用技术
    mysql的锁机制
    JMeter+influxdb+grafana性能测试监控平台
    电商项目之Java8函数式接口落地实践
    easyUI重新渲染
  • 原文地址:https://blog.csdn.net/m0_55834564/article/details/126413701