Shell script to loop through each line in a file

The content of the table_names.conf file is as follows:

teacher
student
class
score

for loop read

#!/bin/bash
echo "=====第一种方法====="
for line in `cat /opt/table_names.conf`
do
  echo $line
done

While loop read

#!/bin/bash
echo "=====第二种方法====="
SYNC_TABLE_NAMES=/opt/table_names.conf; 
while read table
do
	echo $table
done < $SYNC_TABLE_NAMES
# 或while read -r table

Guess you like

Origin blog.csdn.net/u011886447/article/details/104949090