IFS例子

来源:互联网 发布:c语言中问号的用法 编辑:程序博客网 时间:2024/05/24 01:50
#!/bin/bash
#Description: 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;
The output will be:
root's shell is /bin/bash


原创粉丝点击