鸟哥的Linux私房菜(3)

1.一个简单有趣的判断文件是否存在和判断目录的Shell Script:

    #########################################################################
# File Name: sh05.sh
# Author: 
# mail: 
# Created Time: 2016年12月14日 星期三 23时38分40秒
#########################################################################
#!/bin/bash
PATH=/bin:/sbin:usr/bin:/usr/sbin:usr/local/bin:/usr/local/sbin:~/bin
export PATH


echo -e "Please input a filename,I will check the filename's type and permission.\n\n"
read -p "Input a filename: " filename
test -z $filename && echo "You must input a file name." && exit 0
test ! -e $filename && echo "The filename '$filename' DO NOT exist" && exit 0
test -f $filename && filetype="regulare file"
test -d $filename && filename="directory"
test -r $filename && perm="readable"
test -w $filename && perm="$perm writable"
test -x $filename && perm="$perm executable"
echo "The filename: $filename is a $filetype"
echo "And the permission are : $perm"

2.一个可以计算退休日期的简单Shell Script:

#########################################################################
# File Name: 
# Author: 
# mail: 
#########################################################################
#!/bin/bash
PATH=/bin:/sbin:usr/bin:/usr/sbin:usr/local/bin:/usr/local/sbin:~/bin

echo "This program will try to caculate :"
echo "How many days before your demobilization date..."
read -p "Please input your demobilization date (YYYYMMDD ex>20170101):" date2
date_d=$(echo $date2 | grep '[0-9]\{8\}') #检测是否有8个数字
if [ "$date_d" == "" ];then
    echo "You input the wrong date format......"
    exit 1
fi
declare -i date_dem=`date --date="$date2" "+%s"`
declare -i date_now=`date "+%s"`
declare -i date_total_s=$(($date_dem-$date_now))
declare -i date_d=$((date_total_s/60/60/24))
if [ "$date_total_s" -lt "0" ];then
    echo "You had been demobilization before: " $((-1*date_d)) " ago"
else
    declare -i date_h=$(($(($date_total_s-$date_d*60*60*24))/60/60))
    echo "You will demobilize after $date_d days and $date_h hours."
fi



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值