在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)
while IFS='' read -r lineRead || [[ -n "$lineRead " ]]; do
<some important code here>
done < "$myfile"
Run Code Online (Sandbox Code Playgroud)
我看到了两个优点
1.这使您免于使用额外的代码行.
2.如果文件非常大,为什么要将其加载到内存中?
| 归档时间: |
|
| 查看次数: |
103 次 |
| 最近记录: |