zoukankan      html  css  js  c++  java
  • Linux 基础与应用教程007(shell)

    1.

    第一个shell脚本

    打开文本编辑器(可以使用 vi/vim 命令来创建文件),新建一个文件 test.sh,扩展名为 sh(sh代表shell),扩展名并不影响脚本执行,见名知意就好,如果你用 php 写 shell 脚本,扩展名就用 php 好了。

    输入一些代码,第一行一般是这样:

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

    #! 是一个约定的标记,它告诉系统这个脚本需要什么解释器来执行,即使用哪一种 Shell。

    echo 命令用于向窗口输出文本。

    运行 Shell 脚本有两种方法:

    1、作为可执行程序

    将上面的代码保存为 test.sh,并 cd 到相应目录:

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

    注意,一定要写成 ./test.sh,而不是 test.sh,运行其它二进制的程序也一样,直接写 test.sh,linux 系统会去 PATH 里寻找有没有叫 test.sh 的,而只有 /bin, /sbin, /usr/bin,/usr/sbin 等在 PATH 里,你的当前目录通常不在 PATH 里,所以写成 test.sh 是会找不到命令的,要用 ./test.sh 告诉系统说,就在当前目录找。

    2、作为解释器参数

    这种运行方式是,直接运行解释器,其参数就是 shell 脚本的文件名,如:

    /bin/sh test.sh

    This moment will nap, you will have a dream; but this moment study, you will interpret a dream.
  • 相关阅读:
    POJ 3140 Contestants Division (树dp)
    POJ 3107 Godfather (树重心)
    POJ 1655 Balancing Act (树的重心)
    HDU 3534 Tree (经典树形dp)
    HDU 1561 The more, The Better (树形dp)
    HDU 1011 Starship Troopers (树dp)
    Light oj 1085
    Light oj 1013
    Light oj 1134
    FZU 2224 An exciting GCD problem(GCD种类预处理+树状数组维护)同hdu5869
  • 原文地址:https://www.cnblogs.com/mawenqi-barry/p/8989237.html
Copyright © 2011-2022 走看看