我正在创建一个 bash 脚本,该脚本应该将所有文件复制~/Development/
到我网络上的另一台计算机。我已启用它来挂载计算机(如果它不在),但我真正的问题是创建文件夹。
我想保存文件/Volumes/Users/Public/InfiniteBackups/Development/
,因此我运行一些 if 语句来检查它们是否存在。
#! /bin/bash
echo "Starting Backup of Development Files"
echo
say "Starting Backup of Development Files"
if [ -d "/Volumes/Users/Public/" ]; then
# Control will enter here if $DIRECTORY exists.
echo "Location is there..."
echo
# Start
echo "Copying Files"
echo
if [ ! -d "/Volumes/Users/Public/InfiniteBackups/Development" ] ; then
echo "/Volumes/Users/Public/InfiniteBackups/Development did not exist."
say "Location did not exist, creating it."
cd /Volumes/Users/Public/
if [ ! -d "/Volumes/Users/Public/InfiniteBackups"]; then
say "InfiniteBackups did not exist, creating it…"
mkdir InfiniteBackups
fi
if [! -d "/Volumes/Users/Public/InfiniteBackups/Development"]; then
cd InfiniteBackups
mkdir Development
fi
fi
cp -v -rip ~/Desktop/ /Volumes/Users/Public/InfiniteBackups/Development
echo "Files have finished transferring"
say "Files have finished transferring"
fi
它会说 /Volumes/Users/Public/ 存在,也会说 /Volumes/Users/Public/InfiniteBackups/Development 不存在。然后它会检查 /Volumes/Users/Public/InfiniteBackups/ 是否存在,但实际上它不应该存在。然后它应该创建目录。然而,它却表现得好像卷确实存在,尽管它显然不存在。
为什么它不起作用?谢谢。
答案1
尝试在“和”之间添加一个空格。您在两个地方都遗漏了这一点。整个测试始终返回非零数字,因为它给出了错误。
我在 Linux 上测试了我的理论,对于 OS X 来说应该也是一样的......