#! /bin/bash
read file1 file2
if [ -f $file1 -a -f $file2 ]&&[ $file1 -nt $file2 ]
then
cat $file1 > $file2
elif [ -f $file1 -a -f $file2 ]&&[ $file2 -nt $file1 ]
then
cat $file2 > $file1
elif [ -f $file1 -a -d $file2 ]
then
mv $file1 ./$file2
elif [ -d $file1 -a -f $file2 ]
then
mv $file2 ./$file1
else
echo nothing
fi

该Bash脚本读取两个文件file1和file2,然后基于文件是否存在、更新时间及类型进行条件判断。如果file1较新,则将其内容覆盖到file2;如果file2较新,则反向操作。如果file1是文件而file2是目录,脚本会将file1移动到file2目录下;反之亦然。在所有条件都不满足的情况下,输出nothing。
1160

被折叠的 条评论
为什么被折叠?



