[英]While loop in bash using variable from txt file
我是bash的新手,并编写了一个脚本来读取存储在文本文件每一行中的变量(这些变量有成千上万个)。 因此,我尝试编写一个脚本,该脚本将读取各行并将解决方案自动输出到屏幕并保存到另一个文本文件中。
./reader.sh > solution.text
我遇到的问题是,目前我在Sheetone.txt中只有1个变量存储用于测试目的,应该花大约2秒钟才能输出所有内容,但它会卡在while循环中,并且不会输出解决方案。
#!/bin/bash
file=Sheetone.txt
while IFS= read -r line
do
echo sh /usr/local/test/bin/test -ID $line -I
done
如注释中所示,您需要为while
循环提供“内容”。 while
构造以一种可以在条件下执行的方式编写; 如果给出了文件,它将继续进行直到read
用尽。
#!/bin/bash
file=Sheetone.txt
while IFS= read -r line
do
echo sh /usr/local/test/bin/test -ID $line -I
done < "$file"
# -----^^^^^^^ a file!
否则,就像没有轮子骑自行车...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.