Bash 在不发送eof的情况下将文件内容放在stdin上
将文件内容放入stdin的典型方式如下:Bash 在不发送eof的情况下将文件内容放在stdin上,bash,fifo,Bash,Fifo,将文件内容放入stdin的典型方式如下: ./command.sh < myfile /command.sh
./command.sh < myfile
/command.sh
这会将myfile的所有内容放在stdin上,然后发送eof。我想在不添加EOF的情况下将内容放在stdin上
对于各种交互式程序,我希望以一系列命令开始程序,然后继续与程序交互。如果没有发送eof,程序将等待更多的输入,然后我可以交互地输入
这在bash中可能吗?我目前的解决方案是将内容扔到剪贴板上,然后粘贴它们。有更好的方法吗?解决这个问题的方法是使用 要停止“倾听”:
请参见
manmkfifo
另一种方法是使用另一个脚本提供输入:
inputer.sh
:
用法
:
只需使用
cat
命令将文件与stdin合并即可:
./command.sh < <(cat myfile -)
cat
命令
cat
表示串联:
(请阅读精细手册;-)
你可以写
cat file1 file2 file3 ... fileN
以及
cat file1 - file2
cat - file1
cat file1 -
根据您的需要…(cat myfile;cat)| sh command.sh请参阅,使用interact命令的expect脚本将是一个更健壮的解决方案。。。。其中
-
代表标准输入。(你可以使用:catmyfile/dev/stdin |命令…
)
cat $1
while read line; do
echo $line
done
sh inputer.sh input_file | sh your-script.sh
./command.sh < <(cat myfile -)
cat myfile - | ./command.sh
man cat
NAME
cat - concatenate files and print on the standard output
SYNOPSIS
cat [OPTION]... [FILE]...
DESCRIPTION
Concatenate FILE(s), or standard input, to standard output.
...
cat file1 file2 file3 ... fileN
cat file1 - file2
cat - file1
cat file1 -