3.终端输入一个C源文件名(.c结尾)判断文件是否有内容,如果没有内容删除文件,如果有编译并执该文件
代码:
#!/bin/bash
read -p '输入一个c文件的文件名:' filename
if [ -s $filename ]
then
gcc $filename
./a.out
else
rm $filename
echo ${filename}文件为空,已删除!
fi
结果
5.终端输入两个文件名,判断哪个文件的时间戳更新
read -p '输入两个文件名:' file1 file2
if [ $file1 -nt $file2 ]
then
echo $file1时间戳更新
else
echo $file2时间戳更新
fi
结果