我一直在编写代码,以实现对文件夹和文件进行密码保护、压缩和归档的自动化。但是,这段代码似乎不喜欢我。
我逐行运行它,但它总是在zip命令上出错,即使$file
和$source
都是正确和有效的。
有什么想法吗?
以下是源代码:
#!/bin/bash
echo "Drag in the source file"
read source
echo
echo "Drag in the destination file, or press enter to select the Desktop"
read destination
echo
if [ -z "$destination" ]
then destination="$PWD/Desktop"
echo "Destination is set to the desktop"
fi
echo "Type the name of the file to make"
read file
if [ -z "$file" ]
then file="archive"
echo "File name set to archive.zip"
fi
file="${destination}/${file}"
if [ -d $"source" ]
then zip -erj "$file" "$destination"
else zip -ej "$file" "$destination"
fi
destination="$PWD/Desktop"
-- 这不是桌面。$PWD
是当前工作目录,它可以是任何东西。桌面是$HOME/Desktop
。这可能是错误的一个原因,因为如果目标目录不存在,zip
不会创建目标目录。此外,似乎您要求zip
归档$destination
而不是$source
。 - axiaczip 目标 源
。 - Dashel Peters