메뉴에 보니까 적당한 카테고리를 찾기가 힘들어서 이렇게 기타란에 올립니다!
#!/bin/sh
echo "Is it morning? Please answer yes or no"
read timeofday
case $timeofday in
"yes" | "y" | "Yes" | "YES" ) echo "Good morning";;
"n*" | "N*" ) echo "Good afternoon";;
* ) echo "Sorry, answer not recognised";;
esac
exit 0
여기서 쉘 실행후
No를 치면 에 해당하는 Sorry~부분이 나옵니다
N을 정확히 쳐야 Good Afternoon이 나오는데요
N이나 n으로 시작하는 모든 것에 Goodafternoon을 걸려면 어떻게 해야하나요?
학교공부하다가 나온것이라 교재도 없네요… 정말 쉬운 것 같은데 몰라서 질문드립니다^^
예문이 무척 익은 예문이라… 찾아보니 전에 봤던 책에 있던 예문을 그대로 사용했더군요…
(Beginning)Linux programming : 한국어판 이 책인것같네요… 도서관에서 빌려서 복사해서
본거라… 암튼… 기회가 있다면 이 책을 한번 보시기을 바랍니다…
이 책이 내린 답은 이렇습니다…
#! /bin/sh
echo "Is it morning? Please answer yes or no"
read timeofday
case $timeofday in
"yes" | "y" | "Yes" | "YES" ) echo "Good morning";;
"n*" | "N*" ) echo "Good afternoon";;
* ) echo "Sorry, answer not recognised";;
yes | y | yes | YES )
echo "Good morning";;
[nN]*)
echo "Good afternoon";;
- )
echo "Sorry, answer not recognised";;
esac
exit 0
결과는 다음과 같습니다…
Is it morning? Please answer yes or no
no
Good afternoon
wewoori@wewoori-G31T-M7:/tmp$ ./test
Is it morning? Please answer yes or no
n
Good afternoon
wewoori@wewoori-G31T-M7:/tmp$ ./test
Is it morning? Please answer yes or no
N
Good afternoon
wewoori@wewoori-G31T-M7:/tmp$ ./test
Is it morning? Please answer yes or no
NO
Good afternoon
wewoori@wewoori-G31T-M7:/tmp$ ./test
Is it morning? Please answer yes or no
yes
Good morning
심지어…
Is it morning? Please answer yes or no
NOOOO
Good afternoon
이렇게됩니다… 즉 대문자 N 소문자 n의 시작되는 단어가
나오면 무조건 결과값은 Good afternoon 이 나오게됩니다…
위에 yes쪽도 그렇게 바꿔주시면 됩니다…
[yY]* ) 이렇게 말이죠…
그리고 한가지 도움이 될련지 모르겠지만 스크립터을 짤때 한줄로 나열식으로
적으셨는데 저 처럼 탭을 이용을 해서 약간 공백을 조금씩 달리주면서 하면
문장보기도 깨끗할뿐아니라 스크립터가 길어져서 문제발생시 찾기도 조금 더
쉬워집니다…옛날 php 배울때 그렇게 안한다고 구박했던 강사분이 있었거든요.
난 그냥 그게 편한게… 근데… 나중엔 알겠더군요…처음 배울때 그런 습관은 중요한거니깐요…
작은 도움이나마 되셨으면 합니다… 즐거운 하루되세요… 비오는데 감기 조심하시구요…