![如果-else 與非空目錄](https://rvso.com/image/1072586/%E5%A6%82%E6%9E%9C-else%20%E8%88%87%E9%9D%9E%E7%A9%BA%E7%9B%AE%E9%8C%84.png)
我想在 bash 腳本中從 github 安裝一些東西,但我嘗試驗證該資料夾是否存在:
BLUE "Installing LS_COLORS..."
if [ ! -d "~/opt/LS_COLORS" ]
then
git clone https://github.com/trapd00r/LS_COLORS.git ~/opt/LS_COLORS && cd ~/opt/LS_COLORS
cat lscolors.sh >> ~/.bashrc
source ~/.bashrc
else
GREEN "LS_COLORS already installed"
fi
問題是 LS_COLORS 目錄不為空,並且無法正常運作。我無法進入其他部分。
答案1
看起來路徑不正確,我在所有地方添加了完整路徑:
BLUE "Installing LS_COLORS..."
if [ ! -d "/home/torabi12/opt/LS_COLORS/" ]
then
git clone https://github.com/trapd00r/LS_COLORS.git /home/torabi12/opt/LS_COLORS
cat /home/torabi12/opt/LS_COLORS/lscolors.sh >> ~/.bashrc
source ~/.bashrc
else
GREEN "LS_COLORS already installed"
fi
現在它正在發揮作用。感謝您的所有回覆。