오늘은 대한입니다.
sun's longitude:299 44 13.10 
· 자유게시판 · 묻고답하기 · 알파문서 · RPMS list
· 사용자문서 · 팁/FAQ모음 · 리눅스Links · 자료실
· 서버정보 · 운영자 · Books/FAQ · FreeBSD
/board/read.php:소스보기  
알파문서
자주 잊어먹거나, 메모해 둘 필요성이 있는 팁이나 문서, 기타 등등
[*** 쓰기 금지단어 패턴 ***]
글 본문 중간에 업로드할 이미지를 추가하는 방법 : @@이미지이름@@
ex) @@foo.gif@@
108 번 글: [SHELL] 라인단위로 읽어오기
글쓴이: 산이 [홈페이지] 글쓴날: 2005년 01월 02일 05:57:22 일(새벽) 조회: 3706
-- example.sh -----------------------------
#!/bin/sh

OIFS=$IFS

TT="10
  21 22 23 2444444444444444
30 31

50


  61
70
"

echo '------------------------------------'
echo 'orignal string'
echo "$TT"
echo '------------------------------------'

echo '------------------------------------'
echo 'for() test with default IFS'
echo '------------------------------------'

for n in $TT ; do
  echo "'$n'"
done

IFS='
'
echo '------------------------------------'
echo 'for() test with \r\n IFS'
echo '------------------------------------'

for n in $TT ; do
  echo "'$n'"
done

IFS=$OIFS
echo '------------------------------------'
echo 'pipe and read test with default IFS'
echo '------------------------------------'

echo "$TT" | while read line etc ; do
  echo "'$line' '$etc'"
done

IFS='
'
echo '------------------------------------'
echo 'pipe and read test with \r\n IFS'
echo '------------------------------------'

echo "$TT" | while read line etc ; do
  echo "'$line' '$etc'"
done

IFS=$OIFS
echo '------------------------------------'
echo 'stdin read file with default IFS'
echo '------------------------------------'

while read line etc ; do
  echo "'$line' '$etc'"
done < /tmp/foo.txt

IFS='
'
echo '------------------------------------'
echo 'stdin read file with \r\n IFS'
echo '------------------------------------'

while read line etc ; do
  echo "'$line' '$etc'"
done < /tmp/foo.txt

IFS=$OIFS
echo '------------------------------------'
echo 'single line read with default IFS'
echo '------------------------------------'

echo "some foo bar comment" |
{
  read first second others
  echo "'${first}' '${second}' '${others}'"
}

IFS='
'
echo '------------------------------------'
echo 'single line read with default IFS'
echo '------------------------------------'

echo "some foo bar comment" |
{
  read first second others
  echo "'${first}' '${second}' '${others}'"
}

echo
echo "external variable test: '${first}'" ## is empty

exit 0
---------------------------------------------------

// result

------------------------------------
orignal string
------------------------------------
10
  21 22 23 2444444444444444
30 31

50


  61
70

------------------------------------
for() test with default IFS
------------------------------------
'10'
'21'
'22'
'23'
'2444444444444444'
'30'
'31'
'50'
'61'
'70'
------------------------------------
for() test with \r\n IFS
------------------------------------
'10'
'  21 22 23 2444444444444444'
'30 31'
'50'
'  61'
'70'
------------------------------------
pipe and read test with default IFS
------------------------------------
'10' ''
'21' '22 23 2444444444444444'
'30' '31'
'' ''
'50' ''
'' ''
'' ''
'61' ''
'70' ''
'' ''
------------------------------------
pipe and read test with \r\n IFS
------------------------------------
'10' ''
'  21 22 23 2444444444444444' ''
'30 31' ''
'' ''
'50' ''
'' ''
'' ''
'  61' ''
'70' ''
'' ''
------------------------------------
stdin read file with default IFS
------------------------------------
'111' '22222'
'file' ''
'foo' ''
------------------------------------
stdin read file with \r\n IFS
------------------------------------
'111 22222' ''
'  file' ''
'foo' ''
------------------------------------
single line read with default IFS
------------------------------------
'some' 'foo' 'bar comment'
------------------------------------
single line read with default IFS
------------------------------------
'some foo bar comment' '' ''

external variable test: ''

 
이전글 : [MySQL] mysql memory setting table
다음글 : [PHP & SHELL] daemon mode -- background  
 from 61.254.75.78
JS(Redhands)Board 0.4 +@

|글쓰기| |답장쓰기| |수정| |삭제|
|이전글| |다음글| |목록보기|
인쇄용 

apache lighttpd linuxchannel.net 
Copyright 1997-2026. linuxchannel.net. All rights reserved.

Page loading: 0.01(server) + (network) + (browser) seconds