![비어 있지 않은 디렉토리가 있는 If-else](https://rvso.com/image/1072586/%EB%B9%84%EC%96%B4%20%EC%9E%88%EC%A7%80%20%EC%95%8A%EC%9D%80%20%EB%94%94%EB%A0%89%ED%86%A0%EB%A6%AC%EA%B0%80%20%EC%9E%88%EB%8A%94%20If-else.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 디렉토리가 비어 있지 않아 제대로 작동하지 않는다는 것입니다. 나는 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
이제 작동 중입니다. 모든 답변에 감사드립니다.