码迷,mamicode.com
首页 > 系统相关 > 详细

shell IFS例子

时间:2016-07-01 23:11:34      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:ifs

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例子

标签:ifs

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!