bash-cheatsheet
IF-ELSE
if [ ! -d "$HOME/file" ]; then
echo "no file exits!"
fi
- 특정 디렉토리에 폴더/파일이 존재하는지 확인
if [ $var == 'str' ]; then
echo "string matches!"
fi
- 변수와 문자열을 비교
printf "\033[33mChecking Start...\033[0m\n"
- 노란색으로 출력
printf
vs echo
- echo는 default로 newline을 보내고, printf는 보내지 않는다.
- formatting 등등의 옵션이 printf에 더 많다.
- reference
check os type
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# linux
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
else
# Unknown.
fi
run another script in current script
sh another_scipt.sh
choice
read -p "Proceed (y/n [n])? " choice
case "$choice" in
y|Y )
echo "Yes"
;;
n|N|"" )
echo "No"
esac