Shell(4): Shell脚本从文件中读取内容的方法

Shell(4): Shell脚本从文件中读取内容的方法

一、使用for方法读取文件内容

#!/bin/bash

for line in `cat 文件名`

do

....

done

二、使用while循环结合read命令逐行读取文件内容

1、方法1

cat "文件名" | while read line

do

done

2、方法2

exec < demo.txt //读取文件

while read line

do

........

done

3、方法3

while read line

do

........

done

参考:linux shell脚本中读取文件内容的方法(含效率测试)_storyteller的博客-CSDN博客_linux shell 读取文本

相关推荐

我的Linux電腦必裝軟體 (2025年版)
bt365体育在线官网

我的Linux電腦必裝軟體 (2025年版)

⏱️ 10-02 ⭐ 4334
梦幻西游飞天密信任务流程
bt365体育在线官网

梦幻西游飞天密信任务流程

⏱️ 10-16 ⭐ 3361
哪里更容易扫出敬业福字?(这些地方出福几率高)
bt365体育在线官网

哪里更容易扫出敬业福字?(这些地方出福几率高)

⏱️ 06-30 ⭐ 5291