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;

 

相关文章:

  • 2022-12-23
  • 2021-04-09
  • 2022-01-18
  • 2021-12-20
  • 2022-12-23
  • 2022-02-21
  • 2022-12-23
猜你喜欢
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2021-08-10
  • 2021-04-20
  • 2021-12-25
  • 2021-11-03
相关资源
相似解决方案