怎么在脚本中读取自己需要的信息?(如何将文件的一行数据读入一个数组?)

怎么在脚本中读取自己需要的信息?(如何将文件的一行数据读入一个数组?)

有这么一个格式的文件,
test.txt
12345,abcdef,11111,aaaaab
234567,bcdef,222223,bbbbb

我想通过shell脚本读取这个文件,得到入下的结果,

$aa[0]=12345 or $aa[0]=234567
$aa[1]=abcdef or $aa[1]=bcdef
$aa[2]=11111 or $aa[2]=222223
$aa[3]=aaaaab or $aa[3]=bbbbb

要怎么实现啊?

谢谢      
复制内容到剪贴板
代码:
[color=blue]-(guest@mac:tty1)-(tmp)-
[26139 0] %[/color] cat file
12345,abcdef,11111,aaaaab
234567,bcdef,222223,bbbbb
[color=blue]-(guest@mac:tty1)-(tmp)-
[26139 0] %[/color] cat foo.sh
#!/bin/bash

IFS=","
while read -a a; do
    echo "--- line $((++n)) ---"
    for ((i = 0; i < ${#a[@]}; i++)); do
        echo "a[$i]=${a[i]}"
    done
done < file
[color=blue]-(guest@mac:tty1)-(tmp)-
[26139 0] %[/color] ./foo.sh
--- line 1 ---
a[0]=12345
a[1]=abcdef
a[2]=11111
a[3]=aaaaab
--- line 2 ---
a[0]=234567
a[1]=bcdef
a[2]=222223
a[3]=bbbbb
[color=blue]-(guest@mac:tty1)-(tmp)-
[26139 0] %[/color]
      
read -a a;

这一句是什么意思啊??

还有IFS是一个什么变量啊?

谢谢      
复制内容到剪贴板
代码:
read: read [-ers] [-u fd] [-t timeout] [-p prompt] [color=red][-a array][/color] [-n nchars] [-d delim] [name ...]
    One line is read from the standard input, or from file descriptor FD if the
    -u option is supplied, and the first word is assigned to the first NAME,
    the second word to the second NAME, and so on, with leftover words assigned
    to the last NAME.  Only the characters found in $IFS are recognized as word
    delimiters.  If no NAMEs are supplied, the line read is stored in the REPLY
    variable.  If the -r option is given, this signifies `raw' input, and
    backslash escaping is disabled.  The -d option causes read to continue
    until the first character of DELIM is read, rather than newline.  If the -p
    option is supplied, the string PROMPT is output without a trailing newline
    before attempting to read.  [color=red]If -a is supplied, the words read are assigned
    to sequential indices of ARRAY, starting at zero.[/color]  If -e is supplied and
    the shell is interactive, readline is used to obtain the line.  If -n is
    supplied with a non-zero NCHARS argument, read returns after NCHARS
    characters have been read.  The -s option causes input coming from a
    terminal to not be echoed.

    The -t option causes read to time out and return failure if a complete line
    of input is not read within TIMEOUT seconds.  If the TMOUT variable is set,
    its value is the default timeout.  The return code is zero, unless end-of-file
    is encountered, read times out, or an invalid file descriptor is supplied as
    the argument to -u.
      
复制内容到剪贴板
代码:
       [color=red]IFS[/color]    The Internal Field Separator that is  used  for  word  splitting
              after  expansion  and  to  split  lines into words with the read
              builtin  command.   The  default  value  is  ``<space><tab><new-
              line>''.
      
请问dearvoid,done<file,怎么解释?      
复制内容到剪贴板
代码:
#!/bin/bash

IFS=","
while read -a a; do
    echo "--- line $((++n)) ---"
    for ((i = 0; i < ${#a[@]}; i++)); do
        echo "a[$i]=${a[i]}"
    done
done < file  [color=red]# 这个重定向作用于整个 while 循环[/color]
      
感谢楼主发贴。学到东西了