重定向的问题 (exec 和 redirection)

重定向的问题 (exec 和 redirection)

复制内容到剪贴板
代码:
#!/bin/bash

if [ $# -ne 1 ]
then
   echo "Enter the file name."
else
   echo "Enter the student name:"
   read student
   while [ $student != "end" ]
   do
       echo "Enter the score:"
       read score
       echo $student $score >>$1
       echo "Enter the student name:
       read student
   done
   exec 10<&$1
   while [  ! -z $student ]
   do
       read -u 10 $student $score
       echo $student $score
    done
fi
运行是显示重定向错误,将exec 10 <&$1 改为10 <>$1,即可以运行,为什么?      
复制内容到剪贴板
代码:
[color=blue]-(guest@mac:tty1)-(bash)-
[252 0] %[/color] cat read-u.sh
#! /bin/bash

exec 10< $0
while read -u 10 line; do
    echo "$line"
done
[color=blue]-(guest@mac:tty1)-(bash)-
[252 0] %[/color] ./read-u.sh
#! /bin/bash

exec 10< $0
while read -u 10 line; do
echo "$line"
done
[color=blue]-(guest@mac:tty1)-(bash)-
[252 0] %[/color]
      
复制内容到剪贴板
代码:
[color=blue]-(guest@mac:tty1)-(bash)-
[252 0] %[/color] cat read-u.sh
#! /bin/bash

exec 10< $0
exec 20<&10
while read -u 20 line; do
    echo "$line"
done
[color=blue]-(guest@mac:tty1)-(bash)-
[252 0] %[/color] ./read-u.sh
#! /bin/bash

exec 10< $0
exec 20<&10
while read -u 20 line; do
echo "$line"
done
[color=blue]-(guest@mac:tty1)-(bash)-
[252 0] %[/color]
      
复制内容到剪贴板
代码:
   Redirecting Input
       Redirection of input causes the file whose name results from the expan-
       sion of word to be opened for reading on  file  descriptor  n,  or  the
       standard input (file descriptor 0) if n is not specified.

       The general format for redirecting input is:

              [n]<word

   Duplicating File Descriptors
       The redirection operator

              [n]<&word

       is used to duplicate input file descriptors.  If word expands to one or
       more digits, the file descriptor denoted by n is made to be a  copy  of
       that  file  descriptor.   If  the  digits in word do not specify a file
       descriptor open for input, a redirection error occurs.  If word  evalu-
       ates  to  -,  file  descriptor n is closed.  If n is not specified, the
       standard input (file descriptor 0) is used.

       The operator

              [n]>&word

       is used similarly to duplicate output file descriptors.  If  n  is  not
       specified,  the  standard  output  (file descriptor 1) is used.  If the
       digits in word do not specify a file descriptor open for output, a  re-
       direction  error  occurs.  As a special case, if n is omitted, and word
       does not expand to one or more digits, the standard output and standard
       error are redirected as described previously.
      
只是一个空格吗?我再试一下!      
[QUOTE=TUDOU01]只是一个空格吗?我再试一下![/QUOTE]
观察不够仔细      
明白了!谢谢!