首页 > 系统服务 > 详细

shell脚本使用技巧5--字符分隔

时间:2017-06-10 16:08:57      阅读:267      评论:0      收藏:0      [点我收藏+]
#!/bin/bash
#filename:ifs.sh
data="name,sex,rollon,location"
oldIFS=$IFS
IFS=, 
for item in $data;
do
    echo Item: $item
done

#IFS=$oldIFS

设置IFS为,号分隔符

#!/bin/bash
#filename:fenge.sh
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;

注意:[ ]空格;

shell脚本使用技巧5--字符分隔

原文:http://www.cnblogs.com/hujianglang/p/6978896.html

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