五只简简单单的shell脚本
五只简简单单的shell脚本
#!/bin/bash read -p ‘please enter a username:‘ username #判断参数是否为空 if [ "$username" = "" ]; then echo "please input a username" exit 1 fi #判断用户名是否存在 if grep $username /etc/passwd &> /dev/null; then userid=$(id -u $username) if [ $userid -lt 500 ];then echo "$username is a admin user" else echo "$username is a normal user" fi else echo "$username does not exist" fi
#!/bin/bash sum=0 for i in "" do sum=$[$sum+$i] done echo "$sum"
#!/bin/bash sum=0 for i in "" do for line in $(cat $i) do sum=$[1+$sum] done done echo "$sum"
#!/bin/bash raw_dir="/home/moon/linux-test/test4-dir" #可修改绝对路径; read -p ‘请输入需要移动到的路径:‘ raw_dir mv ./*.c $raw_dir #移动文件 ls -S $raw_dir #按照文件大小对其进行排序输出
#!/bin/bash max=$1 for x in do if [[ $x != *[!0-9]* ]];then if [ $x -gt $max ];then max=$x fi else echo "‘$x‘ is not a number" fi done echo "$max"
相关推荐
huha 2020-10-16
laisean 2020-11-11
大牛牛 2020-10-30
firefaith 2020-10-30
liguojia 2020-10-20
wangzhaotongalex 2020-10-20
以梦为马不负韶华 2020-10-20
JohnYork 2020-10-16
Julyth 2020-10-16
applecarelte 2020-10-16
laisean 2020-09-27
flycappuccino 2020-09-27
liguojia 2020-09-27
wangzhaotongalex 2020-09-22
流年浅滩 2020-10-23
liujianhua 2020-10-22
woaimeinuo 2020-10-21
tufeiax 2020-09-03
laisean 2020-09-01
vvu 2020-09-16
libao 2020-09-16
Yyqingmofeige 2020-08-18
zhushixia 2020-08-17