shell scripts 中,遇到空白怎麼處理? - Linux

Table of Contents

※ 引述《aeolus0829 (archer)》之銘言:
: 我想寫個 scripts ,依照名稱搬移到適當的目錄
: 若目錄不存在,則以名稱命名($F),建立一個新目錄後(/home/user/doc/$A),
: 再搬進去
: shell scripts 如下
: /var/www/html
: drwxr-xr-x 13 root root 4096 2008-06-02 09:06 manual
: drwxr-xr-x 2 root root 4096 2008-06-02 09:06 nut cgi bin
: drwxr-xr-x 5 root root 4096 2009-01-15 13:10 ora doc

: F=`find /var/www/html -type d -print`
: for A in $F; do

上面兩行改成下面兩行

find /var/www/html -type d -print |
while read A; do

: if [ -d /home/user/doc/$A ]; then
: mv $A /home/user/doc
: else
: mkdir /home/user/doc/$A
: mv $A /home/user/doc/
: done
: 問題來了,當這支 scripts 遇到 "nut cgi bin" 時,會把它當成
: nut
: cgi
: bin
: 三個字串
: 我嘗試過在 scripts 中把 $A 用 "$A" 包起來,但沒有作用
: 請問空白該怎麼處理?

--

All Comments

David avatarDavid2009-01-21
神奇!改while 的確可以耶! 非常感謝 .. ^ ^
以前沒用過 while ,看來該來研究一下了
Adele avatarAdele2009-01-24
重點應該是read 不是while吧....@@" 我不會shell script..
Lauren avatarLauren2009-01-29
好像是因為read一次讀取一行 所以不會有被IFS中斷的問題?
Todd Johnson avatarTodd Johnson2009-02-02
如樓上所說,的確是 read 的功勞 .. 囧
原來是我想的太複雜了 :P