shell的疑問 - Linux

Table of Contents

小弟要寫個shell,要先取得passwd裡之uid 在判斷是否印出,
但是在shell中使用for 就會出問題,程式如下(簡化過)

for name in `cat /etc/passwd`
do
echo $name
done

照理會印出跟指令 cat /etc/passwd 的資料一樣,
但實際上確不是這樣,在passwd檔中
dbus:x:81:81:System message bus:/:/sbin/nologin
用shell跑只會印出 message,並不是完整的整行資料.

請問是否也有人遇過這樣的問題.

--

All Comments

Zora avatarZora2014-02-20
權限問題?
Margaret avatarMargaret2014-02-23
我用root 登入的,還需要注意那些呢? tks
Kelly avatarKelly2014-02-24
for會用空白字元(空格 換行)拆詞
Zenobia avatarZenobia2014-02-26
danny大 有何比較好的方式解嗎? tks
Blanche avatarBlanche2014-02-28
改IFS => IFS=$'\n' 這樣就會只用換行拆
Lucy avatarLucy2014-03-03
>_< 感謝 可以了