Shell Script小問題 - Linux

Table of Contents

我寫了一個簡單的shell script

list
--
a b c d e


run.sh
--
#!/bin/sh
str=`cat list`
for s in $str
do
echo $s
done
--


以上的動作是
將list這個檔案的字串顯示在螢幕上
但是如果照上面的作法
我的run.sh跑出來的結果會變成
a
b
c
d
e


而非
a b c d e

他把空白當作斷行看待
請問該怎麼解決這個問題呢@@"


感謝:)

--
thePainter.
◣◢
◤ ◣ http://www.wretch.cc/blog/myelf
◢ ◤ ◤ ◤ Wretch@BBS -> P_myelf
thePainter. φthePainter.

--

All Comments

Erin avatarErin2009-03-19
改IFS環境變數
Megan avatarMegan2009-03-21
改用awk
Doris avatarDoris2009-03-23
echo印出後就會換行,你可以用printf
Carolina Franco avatarCarolina Franco2009-03-26
用 readline 也行
Connor avatarConnor2009-03-29
改用echo -n? (逃
Ethan avatarEthan2009-04-02
感謝m(_ _)m我先試試看好了
Tristan Cohan avatarTristan Cohan2009-04-02
echo 預設印換行,有一個不印換行的選項,用那個就可以了