shell编程之分隔符

      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;

 

posted @ 2013-08-07 10:13  l851654152  阅读(5900)  评论(0编辑  收藏  举报