[英]Basic Bash backup script
我仍在學習如何在bash中編程,為了練習,我試圖做一個“備份腳本”(引用,因為我知道這不是正確的備份),這里是代碼:
#|/bin/bash
sudo mkdir /home/lucas/bkp
echo "Type the path for the directory you want do save"
read directory
if [-d $directory]; then
sudo cp -R $directory /home/lucas/bkp/
else
echo "Path not found"
fi
但是我收到一個錯誤消息,說保存在變量上的路徑不存在,並且直接在外殼上通過“手動”執行相同的命令,一切都很好。 這是錯誤:
lucas@lucas-Linux:~$ sudo sh ./ex.sh
Type the path for the directory you want do save
/home/lucas/git/
./ex.sh: 7: ./ex.sh: [-d: not found
Path not found
您需要在條件中放置空格,如下所示:
if [ -d $directory ]; then
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.