Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 操作系统 > Linux > shell test (from Vbird)
【标  题】:shell test (from Vbird)
【关键字】:shell,test,from,Vbird
【来  源】:http://blog.chinaunix.net/article.php?articleId=55147&blogId=9586

shell test (from Vbird)

Your Ad Here

幾個shell scirpt小程式.

請建立一支 script ,當你執行該 script 的時候,該 script 可以顯示: 1. 你目前的身份 (用 whoami ) 2. 你目前所在的目錄 (用 pwd)
#!/bin/bash
echo -e "Your name is ==> `whoami`"
echo -e "The current directory is ==> `pwd`"

請自行建立一支程式,該程式可以用來計算『您還有幾天可以過生日』啊??
#!/bin/bash
read -p "Pleas input your birthday (MMDD, ex> 0709): " bir
now=`date +%m%d`
if [ "$bir" == "$now" ]; then
echo "Happy Birthday to you!!!"
elif [ "$bir" -gt "$now" ]; then
year=`date +%Y`
total_d=$(($((`date --date="$year$bir" +%s`-`date +%s`))/60/60/24))
echo "Your birthday will be $total_d later"
else
year=$((`date +%Y`+1))
total_d=$(($((`date --date="$year$bir" +%s`-`date +%s`))/60/60/24))
echo "Your birthday will be $total_d later"
fi

讓使用者輸入一個數字,程式可以由 1+2+3... 一直累加到使用者輸入的數字為止。
#!/bin/bash
read -p "Please input an integer number: " number
i=0
s=0
while [ "$i" != "$number" ]
do
i=$(($i+1))
s=$(($s+$i))
done
echo "the result of '1+2+3+...$number' is ==> $s"

撰寫一支程式,他的作用是:
1.) 先查看一下 /root/test/logical 這個名稱是否存在;
2.) 若不存在,則建立一個檔案,使用 touch 來建立,建立完成後離開;
3.) 如果存在的話,判斷該名稱是否為檔案,若為檔案則將之刪除後建立一個檔案,檔名為 logical ,之後離開;
4.) 如果存在的話,而且該名稱為目錄,則移除此目錄!
#!/bin/bash
if [ ! -e logical ]; then      # 1.)
touch logical
echo "Just make a file logical"
exit 1                                           #2.)
elif [ -e logical ] && [ -f logical ]; then    # 3.)
rm logical
mkdir logical
echo "remove file ==> logical"
echo "and make directory logical"
exit 1
elif [ -e logical ] && [ -d logical ]; then   # 4.)
rm -rf logical
echo "remove directory ==> logical"
exit 1
else
echo "Does here have anything?"
fi

我們知道 /etc/passwd 裡面以 : 來分隔,第一欄為帳號名稱。請寫一隻程式,可以將 /etc/passwd 的第一欄取出,而且每一欄都以一行字串『The 1 account is "root" 』來顯示,那個 1 表示行數。
#!/bin/bash
accounts=`cat /etc/passwd | cut -d':' -f1`
for account in $accounts
do
declare -i i=$i+1
echo "The $i account is \"$account\" "
done

automake步骤:【上一篇】
知道了为什么河南那么多人抢劫了:【下一篇】
【相关文章】
  • shell expect 的介绍
  • shell基础(引用连接)
  • Shell精解[收录]
  • shell输入与输出
  • 环境和shell变量
  • example about linux shell
  • something about linux shell 2
  • Win ftp From Unix简单上传下载实例
  • linxu下开发常用的shell脚本
  • Shell编程基础
  • 【随机文章】
  • How does PXE booting work?
  • 图片路径问题解决方案
  • 索引_相册
  • 截取屏幕图像
  • 三大原则--助你更有效的防止病毒侵入
  • Nelder-Mead(simplex,“单纯形”)算法
  • 关于指针的理解
  • 以太网技术大全(3)
  • 通过ASP与ACCESS数据库建立连接(附源码)(2)
  • 《信息系统平台》介绍
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.