Shell 读取时如何从文件和进程中获取长参数列表?
我有一个值列表(当前文件中大约80个),我需要在Bourne Shell脚本中处理这些值,然后使用每个值执行另一个Shell脚本 如果我使用构造Shell 读取时如何从文件和进程中获取长参数列表?,shell,Shell,我有一个值列表(当前文件中大约80个),我需要在Bourne Shell脚本中处理这些值,然后使用每个值执行另一个Shell脚本 如果我使用构造 read parameter do some processing call other shell script using parameter done < data_file.lst 读取参数 做 一些加工 使用参数调用其他shell脚本 完成
read parameter
do
some processing
call other shell script using parameter
done < data_file.lst
读取参数
做
一些加工
使用参数调用其他shell脚本
完成
那么,在do done循环中执行的任何代码都没有与之关联的tty。这意味着被调用的shell脚本将无法运行,该脚本将测试tty执行某些tput处理
我不想对'cat data_file.lst`方法中的参数使用,该方法保留连接到tty的stdin和stdout,因为存在一种危险,即随着值列表的增加,最终将超过最大行长度
那么,有人能提出一种不使用read-do-done处理参数列表的方法吗
或者必须使用xargs调用中间shell脚本来进行处理,然后调用辅助shell脚本?#复制stdin。
# Make copy of stdin.
exec 3<&0
while read parameter; do
some processing
# In sub-shell restore original stdin, then execute command.
(exec 0<&3; command that needs tty)
done < data_file.lst
exec 3使用不同的文件句柄进行读取:
while read parameter <&3
do
some processing
call other shell script using parameter
done 3< data_file.lst
一边读参数,谢谢!问题解决了。我将把这个添加到我的技巧列表中。谢谢!这是我没有考虑过的方法。