'Shell script'에 해당되는 글 5건

  1. 2015.07.15 read yes or no
  2. 2015.07.15 I/ORedirection
  3. 2015.07.15 함수 콜.
  4. 2015.07.15 string split
  5. 2015.07.15 error token is "08"

read yes or no

Shell script 2015. 7. 15. 15:28

키보드에서 Y/N를 입력 받을때... 


read -p "Is this a good question (y/n)? " answer
case ${answer:0:1} in
    y|Y )
        echo Yes
    ;;
    * )
        echo No
    ;;
esac

'Shell script' 카테고리의 다른 글

I/ORedirection  (0) 2015.07.15
함수 콜.  (0) 2015.07.15
string split  (0) 2015.07.15
error token is "08"  (0) 2015.07.15
Posted by iRang1101
,

I/ORedirection

Shell script 2015. 7. 15. 15:26

#파일의 입력. 출력. 

exec < FILE

echo "Hello" > FILE


#파일의 close

exec 0<&-

       
exec 3< $TMP_CRONTAB
read   min hour day mon week cmd <&3
#.....
exec 3<&-
read -p "Do you wish to install this program? (y/n)? " answer

exec 3<&- 요걸 안하면.. 
두번째 read에서 키보드 입력을 기다리지 않는다. 

첫번째 exec 3< $TMP_CRONTAB 요기에서 읽어 들인 파일 내용이 answer로 들어가기 때문이다. 



'Shell script' 카테고리의 다른 글

read yes or no  (0) 2015.07.15
함수 콜.  (0) 2015.07.15
string split  (0) 2015.07.15
error token is "08"  (0) 2015.07.15
Posted by iRang1101
,

함수 콜.

Shell script 2015. 7. 15. 10:14
     
echo "Hello~"

printString()
{
echo "print string ${1} ${2}"
}

printString 1 2


./test.sh

Hello~

print string 1 2


함수 안에서의 $1 $2 는 함수 콜할때의 parameter이다. 

'Shell script' 카테고리의 다른 글

read yes or no  (0) 2015.07.15
I/ORedirection  (0) 2015.07.15
string split  (0) 2015.07.15
error token is "08"  (0) 2015.07.15
Posted by iRang1101
,

string split

Shell script 2015. 7. 15. 09:43

문자열을 특정 문자로 나눌때... 


TEST="07.15"

ARRAY=(${STARTDATE//./ })

if [  ${#ARRAY[@]} -eq 2 ]   # array갯수. 판단. 

${ARRAY[0]}   # array 접근. 



'Shell script' 카테고리의 다른 글

read yes or no  (0) 2015.07.15
I/ORedirection  (0) 2015.07.15
함수 콜.  (0) 2015.07.15
error token is "08"  (0) 2015.07.15
Posted by iRang1101
,

error token is "08"

Shell script 2015. 7. 15. 09:36

./test.sh: line 121: [[: 08: value too great for base (error token is "08")


변수가 08일때... 수식으로 비교하면 나오는 에러. 

TEST="08"

if [[ $TEST -gt 0 && $TEST -lt 12 ]]

then

.....

fi



앞에 0이 있어서 생기는 문제. 


해결 : 

${TEST#0}


if [[ ${TEST#0} -gt 0 && ${TEST#0} -lt 12 ]]



'Shell script' 카테고리의 다른 글

read yes or no  (0) 2015.07.15
I/ORedirection  (0) 2015.07.15
함수 콜.  (0) 2015.07.15
string split  (0) 2015.07.15
Posted by iRang1101
,