#!/bin/bash
read -p "请输入一个文件名:" fname
len=`expr length $fname`
s1=`expr index $fname .`
var=`expr substr $fname $((s1+1)) $((len-s1)) `
if [ "$var" = "sh" ]
then
echo "是脚本文件"
if [ -x "$fname" ]
then
echo "是可执行文件"
bash $fname
else
echo "不可执行"
sudo chmod o+x $fname
fi
else
echo "不是脚本文件"
fi
#!/bin/bash
read -p "请输入第一个文件:" fname1
read -p "请输入第二个文件:" fname2
if [ $fname1 -nt $fname2 ]
then
echo $fname1"时间戳更新"
elif [ $fname1 -ot $fname2 ]
then
echo $fname2"时间戳更新"
else
echo "时间戳一样"
fi
#!/bin/bash
read -p "请输入一个用户名:" user
var=`id $user | cut -d '=' -f 1`
if [ "$var" = "uid" ]
then
echo "用户存在"
else
echo "用户不存在开始创建用户"
sudo adduser $user
id $user
fi
#!/bin/bash
read -p "请输入学生成绩:" age
if [ $age -gt 90 -a $age -le 100 ]
then
echo "A"
elif [ $age -gt 80 -a $age -le 90 ]
then
echo "B"
elif [ $age -gt 70 -a $age -le 80 ]
then
echo "C"
elif [ $age -gt 60 -a $age -le 70 ]
then
echo "D"
else
echo "E"
fi
#!/bin/bash
echo `ls -a /etc | grep -i ^p | wc -l`