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