小编Sin*_*nan的帖子

确定 bash for 循环中的最后一次迭代

我有一个循环将一些行添加到配置文件中:

for i in ${H//,/ }
do
        sed -i "7i\                      host($i) or" $configPath/$g.conf
done
Run Code Online (Sandbox Code Playgroud)

$H 是逗号分隔的变量,例如:host1,host2,host4,host10

它返回以下内容:

                  host(host10) or
                  host(host4) or
                  host(host2) or
                  host(host1) or
Run Code Online (Sandbox Code Playgroud)

但我想要实现的是:

                  host(host10) or
                  host(host4) or
                  host(host2) or
                  host(host1)
Run Code Online (Sandbox Code Playgroud)

或相反亦然:

                  host(host1) or
                  host(host2) or
                  host(host4) or
                  host(host10)
Run Code Online (Sandbox Code Playgroud)

谁能帮助我找到正确的方向,我怎样才能做到这一点?

bash

9
推荐指数
1
解决办法
2万
查看次数

标签 统计

bash ×1