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;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM