首页 > 系统服务 > 详细

shell IFS例子

时间:2016-07-01 23:08:43      阅读:480      评论:0      收藏:0      [点我收藏+]
IFS 就是分割符号,把aa  bb  cc  dd 分开 分别是$0 $1 $2 $3  , 当i=3时,赋值给b   dd。



[root@shell test]# cat 1
#!/bin/bash
A="aa:bb:cc:dd"
IFS=":"
i=0
for  B  in $A;
do 
                [  $i  -eq  3 ]  &&  b=$B;
                let i++;
done;
echo $b;
[root@shell test]# sh 1 
dd
[root@shell 1]# cat 110.sh
#!/bin/bash
#Desc: Illustration of IFS
line="root:x:0:0:root:/root:/bin/bash"
oldIFS=$IFS;
IFS=":"
count=0
for item in $line;
do
     [ $count -eq 0 ]  && user=$item;
     [ $count -eq 6 ]  && shell=$item;
    let count++
done;
IFS=$oldIFS
echo $user\‘s shell is $shell;


本文出自 “何全” 博客,请务必保留此出处http://hequan.blog.51cto.com/5701886/1795015

shell IFS例子

原文:http://hequan.blog.51cto.com/5701886/1795015

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!