使用bash脚本时,"cat"文件是一个无用的步骤吗?

via*_*a77 1 bash file

在bash脚本中读取文件时捕获文件是否无用?

我应该"捕捉"文件,然后将内容发送到"while",如:

myFileContent="$(cat "$myfile")"
while IFS='' read -r lineRead || [[ -n "$lineRead " ]]; do
    <some important code here>
done <<< "$myFileContent"
Run Code Online (Sandbox Code Playgroud)

或者我应该直接发送文件,如:

while IFS='' read -r lineRead || [[ -n "$lineRead " ]]; do
    <some important code here>
done < "$myfile"
Run Code Online (Sandbox Code Playgroud)

CBR*_*CBR 7

while IFS='' read -r lineRead || [[ -n "$lineRead " ]]; do
    <some important code here>
done < "$myfile"
Run Code Online (Sandbox Code Playgroud)

我看到了两个优点
1.这使您免于使用额外的代码行.
2.如果文件非常大,为什么要将其加载到内存中?