C0301 代码块{}的使用,重定向, 从文件中读取行

#!/bin/bash

# 从 /etc/fstab 中读行

File=/etc/fstab

{
    read line1
    read line2
} < $File

# {}代码块, ()命令组, 这两者之间的区别是, 代码块中定义的变量, 在代码块下部是可以访问的, 但是()命令组中定义的内容, 是无法在外部访问的.

echo "First line in $File is: "
echo "$line1"
echo
echo "Second line in $File is: "
echo "$line2"

exit 0

posted @ 2014-04-28 13:59  神之一招  阅读(247)  评论(0)    收藏  举报