脚本整理

编写脚本 checkint.sh,判断用户输入的参数是否为正整数

#! /bin/bash

#Determines whether the parameter is an integer

read -p " Enter your parameters: " NUM

if [[ $NUM =~ [[:digit:]] ]]
    then
    echo "The parameters you enter are integers"
else
    echo "The parameters you enter are not integers"
fi
~     

编写脚本age.sh,判断年龄

#! /bin/bash

read -p "Input your age: " AGE
if [[ ! "$AGE" =~ [[:digit:]]+ ]];then
    echo "please input a digit age"
    exit
elif [[ $AGE -lt 18 ]];then
    echo "好好学习,天天向上"
elif [[ $AGE -le 60 ]];then
    echo "好好工作,努力赚钱"
elif [[ $AGE -le 120 ]];then
    echo "好好享受你的生活"
else
    echo “您是个长寿的人,或者您来自外星球?”
fi

3、编写脚本 filetype.sh,判断用户输入文件路径,显示其文件类型(普通,目录,链接,其它文件类型)

#! /bin/bash

#Determine file type

read -p " Enter your file path: " FILE
if [[ -z "$FILE" ]];then
    echo "Please Enter your file path!!"
elif [[ -d "$FILE" ]];then
    echo "This file is directory file"
elif [[ -f "$FILE" ]];then
    echo "This file is common file"
elif [[ -L "$FILE" ]];then
    echo "This file is chained file"
elif [[ ! -a "$FILE" ]];then
    echo "This is not a file"
else
    echo "This file is Other file types"
fi


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值