linux - 将内容保存在 stdin 中以供另一个脚本读取

标签 linux bash

如果我想编写一个脚本 (A) 以便它调用另一个将从标准输入读取输入的脚本 (B),我如何将文件内容存储到 A 中的标准输入,并在 A 中调用 B 和那么 B 将从标准输入读取输入?

最佳答案

您可以使用管道。 例如: 文件内容:

Michael

scriptA.sh

#!/bin/bash

cat filecontent | ./scriptB.sh

scriptB.sh

#!/bin/bash

read -p "Name:" name
echo "Hello, $name"

当您运行脚本 scriptA.sh 时。输出将是:

[root@localhost ~]# ./scriptA.sh
Hello, Michael

关于linux - 将内容保存在 stdin 中以供另一个脚本读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48273282/

相关文章:

Linux 二进制权限

bash - 如何提高一个人的 bash/命令行技能?

c++ - 从 netlink 套接字请求连接设备列表

linux - 在 CentOS 7 上从源代码构建 apr-utils -- 依赖问题

bash - 从当前目录获取文件并在同一行打印具有相同扩展名的文件

linux - 如何在 linux-shell 中使用 `amp;` 和 `gt;` 命令?

bash - 如何从bash shell脚本运行beeline和hive查询

linux - if比较中加入 "_"的原因 "if [ "_$str"= "_"]; then ....; fi"

linux - 打包 debian 文件 : debian/copyright file format?

c++ - 如何在 Linux 上用 C++ 清除目录内容(基本上,我想做 'rm -rf <directorypath>/*'