shell 脚本执行

    xiaoxiao2025-07-26  13

    Shell 编程跟 java、php 编程一样,只要有一个能编写代码的文本编辑器和一个能解释执行的脚本解释器就可以了。

    Linux 的 Shell 种类众多,常见的有:

    Bourne Shell(/usr/bin/sh或/bin/sh)Bourne Again Shell(/bin/bash)C Shell(/usr/bin/csh)K Shell(/usr/bin/ksh)Shell for Root(/sbin/sh)

    在任意目录创建 xx/xx.sh (ps:后缀可随便写):

    #!/bin/bash echo "Hello World !"

    执行方式1:这种方式必须在文件头部写 #!/bin/bash

    chmod +x ./test.sh #使脚本具有执行权限    /xx/xx.sh #执行脚本()

    执行方式2:这种方式不需要在头部写 #!/bin/bash,因为已经明确解释器了

    /bin/sh xx/xx.sh 或者 sh xx.sh sh -x xx.sh 实现shell脚本逐条语句的跟踪 sh -n xx.sh 不执行脚本,仅进行语法的检查 sh -v xx.sh 执行脚本前,先将脚本的内容输出到屏幕上

    变量:

    bianlaing=“我是变量” //定义变量 ehco ${binaliang} //输出变量 三种for循环写法: 1、 c写法 for i in ((i=;i<=10;i++;)) do echo $i done 2.python写法 for i in {1..10} do echo $i done 3、seq 写法 for i in $(seq 1 10) do echo $i done

     

    最新回复(0)