IFS 就是分割符号,把aa bb cc dd 分开 分别是$0 $1 $2 $3 , 当i=3时,赋值给b dd。 [[email protected] 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; [[email protected] test]# sh 1 dd
[[email protected] 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;
时间: 2024-10-12 21:10:55