Shell script works on Ubuntu but not working on OpenWrt

im trying to use this script

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

the output i get on OpenWRT is

error: couldn't find modem

so the loop ran once only and not sure what numbers it ran because it should have found a modem between 1-10

when using the same code and running on Ubuntu i get this output:

error: couldn't find modem
error: couldn't find modem
error: couldn't find modem
error: couldn't find modem
error: couldn't find modem
error: couldn't find modem
error: couldn't find modem
error: couldn't find modem
error: couldn't find modem
error: couldn't find modem

which is what i expect. my questions is why the same code works on ubuntu but not OpenWRT
OpenWRT Version: OpenWrt 22.03.2 r19803
Running on x86

OpenWrt uses "ash" of BusyBox by default and some features of bash are unavailable.

ash (OpenWrt):

root@OpenWrt:~# echo {1..10}
{1..10}

bash:

$ echo {1..10}
1 2 3 4 5 6 7 8 9 10

alternate on OpenWrt:

for i in $(seq 1 10); do
  (do something)
done
5 Likes

amazing thank you for answering would have took me a while to figure out

busybox (ash and other of its applets) tend to implement the requirements of SUSv4 (~POSIX):
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xcu_chap02.html

3 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.