linux 在带有变量i [closed]的循环上运行bash命令

5kgi1eie  于 2023-03-01  发布在  Linux
关注(0)|答案(1)|浏览(124)

这个问题是由打字错误或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
7天前关闭。
Improve this question
我尝试使用bash在带有变量i的循环中运行一个命令我编写了以下代码:

for i in {1..10}; do
  mmcli -m $i
done

但当它运行时,它只运行一次,我得到以下输出:

error: couldn't find modem

我添加了echo

for i in {1..10}; do
  mmcli -m $i
echo $i
done

我尝试查看i的输出,但得到以下结果

error: couldn't find modem
{1..10}
dphi5xsq

dphi5xsq1#

我在我的ubuntu里运行你的代码:

#!/bin/bash

for i in {1..10}; do
  mmcli -m $i
done

我得到输出:

error: couldn't find modem at '/org/freedesktop/ModemManager1/Modem/1'
error: couldn't find modem at '/org/freedesktop/ModemManager1/Modem/2'
error: couldn't find modem at '/org/freedesktop/ModemManager1/Modem/3'
error: couldn't find modem at '/org/freedesktop/ModemManager1/Modem/4'
error: couldn't find modem at '/org/freedesktop/ModemManager1/Modem/5'
error: couldn't find modem at '/org/freedesktop/ModemManager1/Modem/6'
error: couldn't find modem at '/org/freedesktop/ModemManager1/Modem/7'
error: couldn't find modem at '/org/freedesktop/ModemManager1/Modem/8'
error: couldn't find modem at '/org/freedesktop/ModemManager1/Modem/9'
error: couldn't find modem at '/org/freedesktop/ModemManager1/Modem/10'

它运行了10次。

相关问题