linux - 命令行中的for循环运行bash脚本逐行读取文本文件

标签 linux bash

我有一个 bash 脚本,它要求两个参数之间有一个空格。现在我想通过从文本文件中读取来自动填写命令行中的提示。文本文件包含带有参数组合的列表。

所以我认为在命令行中是这样的;

for line in 'cat text.file' ; do script.sh ; done

这能做到吗?我错过了什么/做错了什么?

感谢您的帮助。

最佳答案

while 循环可能就是您所需要的。将空格分隔的字符串放入文件 text.file :

cat text.file
bingo yankee
bravo delta

然后像下面这样编写有问题的脚本。

#!/bin/bash
while read -r arg1 arg2
do
 /path/to/your/script.sh "$arg1" "$arg2"
done<text.file

关于linux - 命令行中的for循环运行bash脚本逐行读取文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48222123/

相关文章:

linux - 使用变量检查 FTP 状态 - Linux

linux - Sed命令替换文件中的字符串不起作用

r - 如何防止 packrat 在 docker 中的系统库中安装软件包?

git - 如何在 Windows 上的 Git Bash 中设置 rebase

bash - Node.js 执行程序 : best way of killing a child pipe and all of its children

linux - 在 ARM 上编写操作系统时,如何像在 x86 中一样实现基本的 I/O 功能?

linux - 使用 J-Link OpenSDA 固件和 GDB 调试 mBed-OS 5

php - Cron 作业的 .sh 脚本中的好命令

linux - Bash 从类中获取输出

bash - 通过 sed 有条件地通过管道输出