#!/bin/bash
#判断命令行是否代带有两个文件名的参数 if [ "$1" = "" ] || [ "$2" = "" ] then echo "Please enter file name" exit 1 fi #判断目标文件是否存在 if [ -e $2 ] then echo "The file already exists" until [ ! -f $2 ] #监视该文件是否被删除 do sleep 1 done echo "The file have been deleted" fi#执行源文件移动为目标文件的命令
if [ ! `mv $1 $2` ] then echo "mv sucessful" else echo "mv error" fi执行方法:建立两个文件s1,s2。在一个终端中运行程序,在另一个终端中删除文件,则执行结果如下: