【问题标题】:Looping through the content of a file in Bash to get required output在 Bash 中循环文件的内容以获得所需的输出
【发布时间】:2022-09-23 21:09:43
【问题描述】:

好的,伙计们,我想知道是否有人可以帮助我解决我正在苦苦挣扎的循环,首先我想说我几乎没有脚本知识,所以如果我的术语不正确或者我解释得不好,我深表歉意。

我在需要运行的文本文件中有一组命令,我想将其放入循环中。这些命令需要输入到带有一些标志的可执行文件中

文本文件中的命令示例(我希望将其提供给可执行文件的文本文件中的多个命令):

\'add subs supi=imsi-100010004440017 k=xxxx opc=xxxxx algo=milenage\'

我想要的 shell 脚本/循环的输出是:

/usr/XXX/execuable -c \"Command from text file here \" -u Admin -p Admin http://127.0.0.1

mu 当前的 shell 脚本是

#! /bin/bash
Lines=$(cat /usr/pcn/UDM.txt)
for Line in $Lines
    do /usr/pcn/executable -c \"$Line\" -u Admin -p Admin http://127.0.0.1
done

我看到许多其他论坛建议这样做,但我没有运气:

cat /usr/XXX/UDM.txt | while read line; do
    /usr/XXX/executable -c \"$Line\" -u Admin -p Admin http://127.0.0.1
done
  • 单引号实际上在命令文件中吗?

标签: bash loops shell sh script


【解决方案1】:

如果您的 read 支持 -a 标志,

while read -ra line; do
  /usr/XXX/executable -c "${Line[@]}" -u Admin -p Admin http://127.0.0.1
done < /usr/XXX/UDM.txt

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-04
    • 1970-01-01
    • 2021-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-15
    相关资源
    最近更新 更多