1 #!/bin/bash
2 line="root:x:0:0:root:/root:bin/bash"
3 oldIFS=$IFS
4 IFS=":"
5 count=0
6 for item in $line;
7 do
8 [ $count -eq 0 ] && user=$item;
9 [ $count -eq 6 ] && shell=$item;
10 let count++
11 done;
12 IFS=$oldIFS
13 echo $user\'s shell is $shell
"test.sh" 13L, 225C written
[root@localhost shell]# ./test.sh
root's shell is bin/bash
1 #!/bin/bash
2 oldIFS=$IFS
3 IFS=$'\n'
4 for i in `cat /etc/passwd`;
5 do
6 echo $i
7 done;