<分区>
好的,所以我正在做一个 shell 脚本,目的是“安全删除东西”,所以它应该在调用“/safedell.sh file1 file2 file3”时将文件 TAR 并将其发送到我名为 LIXO 的文件夹。 我是一个 shell 新手,所以我会尝试解释我的代码的每一步,以便你们理解它,到目前为止,这是我所拥有的:
#!/bin/bash
#Purpose = Safe delete
#Created on 20-03-2018
#Version 4.0
#START
##Constants##
dir="/home/cunha/LIXO"
#check to see if the imput is a file#
if ! [ -e $1 ]; then`
echo "Not a file!"
exit 0`
fi
###main###
##Cycle FOR so the script accepts multiple file inputs##
for file in "$@"; do
#IF the input file already exist in LIXO#
if [[ -f $dir/$file ]]; then
echo "|||File EXISTS|||"
#IF the input file is newer than the file thats already in LIXO#
if [[ $file -nt $2 ]]; then
echo "file is newer"
fi
else
echo "File doesnt exist, ziping it and moving"
fi
done`
我的问题:所以我在 LIXO 中有 2 个文件,teste1.txt 和 teste2.tar.bz2,我的问题是当我输入 teste2.txt
--> 输入:/safedell teste2.txt
--> 输出:文件不存在,正在压缩...