#!/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;
注意:[ ]空格;
时间: 2024-10-15 16:17:54