欢迎光临益友网(http://www.1uu2.com) 益友网-做linux用户的良师益友

当前位置: 益友网 > Linux常识 > 文章正文

Linux操作系统Shell基础知识

liner 发表于 2008-08-10 08:55 | 来源: | 阅读 300 次

    ◆Shell基础知识

    1、cat /etc/shells
    查看计算机上可用的shell
    2、编写shell,保存为firstscript

    #! /bin/bash

    # This is a test.

    echo -n Your current directory is:

    pwd

    echo $HOME

    echo Your current directory is:

    pwd

    #END.
    3、运行firstscript
    $ /bin/bash firstscript
    如果找不到文件 使用pwd查看当前目录
    $ /bin/bash pwd/firstscript
    可见当前运行结果。
    4、可以修改firstscript为执行
    $chmod a+x firstscript
    此时输入$ ./firstscript即可
    上面的shell没有交换,我们可以进行交互,如下:
    #!/bin/sh

    echo -n Please input your ID:

    read id_var

    echo -n Please input your password:

    read password

    echo User ID = $id_var

    echo password = $password

    if [ $password = "admin" ]; then

    echo “password is right”

    else

    echo “password is wrong”

    fi
    同前面的运行,自己测试。

    ◆命令行中“\”和“–”符号所代表的含义

     \ 如果在行末,是说明本行还未结束,下面一行和本行是一起的意思.
    — 就是选项的开始,一般一个字母的选项用 – 开头,多个字母的就用 — 开头.
    “\”后如果是回车,不换行的话可能省略;但要是其它字符,就不能省略。
    “\”告诉系统后面跟着的字符为原意,不是命令。
    比如有个文件名中带有空格,就要在空格前加一个“\”。

喜欢益友网的文章,那就通过 RSS Feed 功能订阅阅读吧!

我要评论

*

* 绝不会泄露



返回首页 | 关于我们 | 联系我们 | 广告合作 | 网站地图 | 友情链接 | 版权声明 |