1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
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
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
[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;
|
本文转自 295631788 51CTO博客,原文链接:http://blog.51cto.com/hequan/1795015,如需转载请自行联系原作者