비어 있지 않은 디렉토리가 있는 If-else

비어 있지 않은 디렉토리가 있는 If-else

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 디렉토리가 비어 있지 않아 제대로 작동하지 않는다는 것입니다. 나는 else 부분에 들어갈 수 없습니다.

답변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

이제 작동 중입니다. 모든 답변에 감사드립니다.

관련 정보