手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>操作系统>Linux>列表

新手学堂:Linux操作系统Shell基础知识

来源:互联网 作者:west263.com 时间:2008-04-02
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

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

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

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!