我有一个txt文件,其中包含许多类名。
我想在bash脚本中逐行读取这些类名,并将该值分配给变量以在脚本中的另一个命令中全局使用它。
mask
答案 0 :(得分:1)
我假设files.txt
是类文件的列表,每行一个类?
while read class
do : whatver you need with $class
done < files.txt
如果有多个类文件,请使用数组。
不要把所有的都写满。
file_list=( files.txt other.txt ) # put several as needed
for f in "${file_list[@]}" # use proper quoting
do : processing $f # set -x for these to log to stderr
while read class
do : whatver you need with $class
done < "$f"
done
答案 1 :(得分:0)
假设文件中的每一行仅包含一个类名,则应该这样做:
for f in $FILES
do
echo "Processing $f file..."
while read class
do
<something with "$class" >
done < $f
done
答案 2 :(得分:0)
示例1
FILES="files.txt"
cat $FILES | while read class
do
echo $class # Do something with $class
done
示例2,如Paul Hodges所述
FILES="files.txt"
while read class
do
echo $class # Do something with $class
done < $FILES