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

原文地址:https://www.cnblogs.com/moveofgod/p/3696215.html