[英]Can I call an interactive script in orther bash?
For example,there is an interactive script that read user input his name.And then write the name in a file.例如,有一个交互式脚本读取用户输入他的姓名,然后将姓名写入文件中。
#! /bin/bash
read name
echo $name>>name.txt
If I can't change the interactive script, how can I use anothor bash to quote the interactive script?如果无法更改交互脚本,如何使用另一个 bash 来引用交互脚本?
For example,I want to write a bash that extracts the name from a text and then calls this interactive script.例如,我想写一个 bash 从文本中提取名称然后调用这个交互式脚本。
So can I achieve my idea?那我能实现我的想法吗?
Use a pipe to combine output of one program with the input of the next program:使用pipe将一个程序的 output 与下一个程序的输入结合起来:
echo 'name from other script' | ./script1.sh
echo
can be replaced with any other executable file or script: echo
可以替换为任何其他可执行文件或脚本:
$ cat >script2.sh
#!/bin/sh
echo 'first input'
echo 'second input'
^D
$ chmod u+x script2.sh
$ ./script2.sh | ./script1.sh
If your intended input name is already in a file, use IO redirection instead:如果您的预期输入名称已在文件中,请改用IO 重定向:
$ ./script2.sh < file_containing_name.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.