五只简简单单的shell脚本

五只简简单单的shell脚本

1586596899050

#!/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

img

1586596936642

#!/bin/bash
sum=0
for i in "$@"
do
	sum=$[$sum+$i]
done

echo "$sum"

img

1586596960943

#!/bin/bash

sum=0
for i in "$@"
do
	for line in $(cat $i)
	do
		sum=$[1+$sum]
	done
done

echo "$sum"

img

1586596978581

#!/bin/bash

raw_dir="/home/moon/linux-test/test4-dir"  #可修改绝对路径;

read -p '请输入需要移动到的路径:' raw_dir

mv ./*.c $raw_dir  #移动文件

ls -S $raw_dir	#按照文件大小对其进行排序输出

img

1586596993799

#!/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"

img

猜你喜欢

转载自www.cnblogs.com/lightice/p/12681191.html