shell 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;


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章