学会思考
刻意练习
#!/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;

注意:[ ]空格;

posted on 2017-06-10 15:30  Worty  阅读(533)  评论(0)    收藏  举报