▶ 변수를 세개를 만들어준다. 그리고 이것은 밖에서 받는 것이다.
echo " printing color "
echo $1
echo $2
echo $0
echo " printing color "
echo $1
echo $2
echo $0
~
~
~
~
~
"pos.sh" [새 파일] 5 줄, 49 자
multihp1:/data2/unix/unix10/shell>chmod +x pos.sh
multihp1:/data2/unix/unix10/shell>./pos.sh red blue white <-- red, blue를 받는다. $0은 기본적으로 shell 정보가 들어옴
printing color
red
blue
./pos.sh
~
~
~
~
"pos.sh" [새 파일] 5 줄, 49 자
multihp1:/data2/unix/unix10/shell>chmod +x pos.sh
multihp1:/data2/unix/unix10/shell>./pos.sh red blue white <-- red, blue를 받는다. $0은 기본적으로 shell 정보가 들어옴
printing color
red
blue
./pos.sh
▶
multihp1:/data2/unix/unix10/shell>./pos.sh a c d e
printing color
a
c
./pos.sh
multihp1:/data2/unix/unix10/shell>./pos.sh a c d e
printing color
a
c
./pos.sh
▶ read는 키보드로 입력받는 다는 말이다.
multihp1:/data2/unix/unix10/shell>read A
100
multihp1:/data2/unix/unix10/shell>echo $A
100
multihp1:/data2/unix/unix10/shell>read A B C
100 200 300
multihp1:/data2/unix/unix10/shell>echo $A $B $C
100 200 300
multihp1:/data2/unix/unix10/shell>read AA BB CC <--- 변수는 3개인데 입력되는 값 5개 그러면 300 400 500이 모두 CC에 들어감
100 200 300 400 500
multihp1:/data2/unix/unix10/shell>echo $AA
100
multihp1:/data2/unix/unix10/shell>echo $BB
200
multihp1:/data2/unix/unix10/shell>echo $CC
300 400 500
100
multihp1:/data2/unix/unix10/shell>echo $BB
200
multihp1:/data2/unix/unix10/shell>echo $CC
300 400 500
multihp1:/data2/unix/unix10/shell>read AA BB CC DD <--- 그래서 보통 read를 셋팅할 때 3개의 변수가 필요하다면 잉여변수 하나를 추가해서 만듬
100 200 300 400 500 600 700
100 200 300 400 500 600 700
multihp1:/data2/unix/unix10/shell>echo $AA
100
multihp1:/data2/unix/unix10/shell>echo $BB
200
multihp1:/data2/unix/unix10/shell>echo $CC
300
multihp1:/data2/unix/unix10/shell>echo $DD
400 500 600 700
multihp1:/data2/unix/unix10/shell>
100
multihp1:/data2/unix/unix10/shell>echo $BB
200
multihp1:/data2/unix/unix10/shell>echo $CC
300
multihp1:/data2/unix/unix10/shell>echo $DD
400 500 600 700
multihp1:/data2/unix/unix10/shell>
▶ sysout처럼 사용하는 기능
echo "input user name ==> \c"
read name
echo $name
~
~
~
~
~
"read.sh" [새 파일] 4 줄, 52 자
multihp1:/data2/unix/unix10/shell>chmod +x read.sh
multihp1:/data2/unix/unix10/shell>./read.sh
input user name ==> suho
suho
~
~
~
~
"read.sh" [새 파일] 4 줄, 52 자
multihp1:/data2/unix/unix10/shell>chmod +x read.sh
multihp1:/data2/unix/unix10/shell>./read.sh
input user name ==> suho
suho
echo "What's your name?"
read myname
echo "My name is $myname"
cur_date = 'date'
echo "Today is $cur_date"
~
~
~
"ash.sh" [새 파일] 6 줄, 108 자
multihp1:/data2/unix/unix10/shell>./ash.sh
ksh: ./ash.sh: cannot execute
multihp1:/data2/unix/unix10/shell>chmod +x ash.sh
multihp1:/data2/unix/unix10/shell>./ash.sh
What's your name?
ahnsuho
My name is ahnsuho
./ash.sh[4]: cur_date: not found
Today is
~
~
"ash.sh" [새 파일] 6 줄, 108 자
multihp1:/data2/unix/unix10/shell>./ash.sh
ksh: ./ash.sh: cannot execute
multihp1:/data2/unix/unix10/shell>chmod +x ash.sh
multihp1:/data2/unix/unix10/shell>./ash.sh
What's your name?
ahnsuho
My name is ahnsuho
./ash.sh[4]: cur_date: not found
Today is
multihp1:/data2/unix/unix10/shell>test -f ~/.profile
multihp1:/data2/unix/unix10/shell>echo $?
0
multihp1:/data2/unix/unix10/shell>test -d ~/.profile
multihp1:/data2/unix/unix10/shell>echo $?
1
multihp1:/data2/unix/unix10/shell>echo $?
0
multihp1:/data2/unix/unix10/shell>test -d ~/.profile
multihp1:/data2/unix/unix10/shell>echo $?
1
multihp1:/data2/unix/unix10/shell>a=100
multihp1:/data2/unix/unix10/shell>b=200
multihp1:/data2/unix/unix10/shell>[ $a -lt $b ]
multihp1:/data2/unix/unix10/shell>echo $?
0
multihp1:/data2/unix/unix10/shell>[ "$a" = "$b" ]
multihp1:/data2/unix/unix10/shell>echo $?
1
-z 문자열 : 문자열의 길이가 0이면 참
-n 문자열 : 문자열의 길이가 0이 아니면 참
multihp1:/data2/unix/unix10/shell>[ -z $a ]
multihp1:/data2/unix/unix10/shell>echo $?
1
multihp1:/data2/unix/unix10/shell>[ -n $a ]
multihp1:/data2/unix/unix10/shell>echo $?
0
multihp1:/data2/unix/unix10/shell>mkdir suhodir
multihp1:/data2/unix/unix10/shell>touch suhofile
multihp1:/data2/unix/unix10/shell>[ -f suhodir ]
multihp1:/data2/unix/unix10/shell>echo $?
1
multihp1:/data2/unix/unix10/shell>[ -d suhodir ]
multihp1:/data2/unix/unix10/shell>echo $?
0
multihp1:/data2/unix/unix10/shell>[ -s suhofile ]
multihp1:/data2/unix/unix10/shell>echo $?
1
multihp1:/data2/unix/unix10/shell>touch suhofile
multihp1:/data2/unix/unix10/shell>[ -f suhodir ]
multihp1:/data2/unix/unix10/shell>echo $?
1
multihp1:/data2/unix/unix10/shell>[ -d suhodir ]
multihp1:/data2/unix/unix10/shell>echo $?
0
multihp1:/data2/unix/unix10/shell>[ -s suhofile ]
multihp1:/data2/unix/unix10/shell>echo $?
1
==========================================================================
echo "User Name?" --> echo "User Nmae ==>\c"
read uname
who | grep $uname>/dev/null 2>&1 ---> 정상은 null로 해서 휘발시키고
if [ $? = 0 ]
then
echo "$uname is log on"
else
echo "$uname no log on"
fi
~
~
~
"user.sh" [새 파일] 10 줄, 141 자
multihp1:/data2/unix/unix10/shell>./user.sh
ksh: ./user.sh: cannot execute
multihp1:/data2/unix/unix10/shell>. /user.sh
ksh: /user.sh: not found
multihp1:/data2/unix/unix10/shell>chmod a+x user.sh
chmod: 모드가 잘못되었습니다.
multihp1:/data2/unix/unix10/shell>chmod +x user.sh
multihp1:/data2/unix/unix10/shell>. /user.sh
ksh: /user.sh: not found
multihp1:/data2/unix/unix10/shell>./user.sh
User Name?
ahnsuho
ahnsuho no log on
~
~
"user.sh" [새 파일] 10 줄, 141 자
multihp1:/data2/unix/unix10/shell>./user.sh
ksh: ./user.sh: cannot execute
multihp1:/data2/unix/unix10/shell>. /user.sh
ksh: /user.sh: not found
multihp1:/data2/unix/unix10/shell>chmod a+x user.sh
chmod: 모드가 잘못되었습니다.
multihp1:/data2/unix/unix10/shell>chmod +x user.sh
multihp1:/data2/unix/unix10/shell>. /user.sh
ksh: /user.sh: not found
multihp1:/data2/unix/unix10/shell>./user.sh
User Name?
ahnsuho
ahnsuho no log on
================================================================================
case $1 in
start) sleep 10000&
echo "my sleep is running";;
stop) pid=$(ps | grep sleep | cut -c1-6)
kill $pid
case $1 in
start) sleep 10000&
echo "my sleep is running";;
stop) pid=$(ps | grep sleep | cut -c1-6)
kill $pid
echo " sleep killed !!!";;
*) echo " usage: proc.sh[start|stop]" ;;
esac
start) sleep 10000&
echo "my sleep is running";;
stop) pid=$(ps | grep sleep | cut -c1-6)
kill $pid
case $1 in
start) sleep 10000&
echo "my sleep is running";;
stop) pid=$(ps | grep sleep | cut -c1-6)
kill $pid
echo " sleep killed !!!";;
*) echo " usage: proc.sh[start|stop]" ;;
esac
~
~
~
~
"proc.sh" 10 줄, 189 자
multihp1:/data2/unix/unix10/shell>./proc.sh
usage: proc.sh[start|stop]
multihp1:/data2/unix/unix10/shell>
multihp1:/data2/unix/unix10/shell>./proc.sh start
my sleep is running
multihp1:/data2/unix/unix10/shell>ps
PID TTY TIME COMMAND
28446 pts/tX 0:00 ps
25113 pts/tX 0:00 ksh
25112 pts/tX 0:00 telnetd
28444 pts/tX 0:00 sleep
multihp1:/data2/unix/unix10/shell>./proc.sh stop
sleep killed !!!
multihp1:/data2/unix/unix10/shell>ps
PID TTY TIME COMMAND
25113 pts/tX 0:00 ksh
25112 pts/tX 0:00 telnetd
28466 pts/tX 0:00 ps
이 글은 스프링노트에서 작성되었습니다.
'04번. IT 힌트얻기 > ▶ UNIX' 카테고리의 다른 글
Unix-basic-06 (1) | 2011.11.24 |
---|---|
Unix-basic-09(shell) (0) | 2011.11.24 |
Unix-basic-08 (0) | 2011.11.24 |
Unix-basic-05 (0) | 2011.11.23 |
Unix-Basic-04 (0) | 2011.11.22 |