Running UCI command inside for loop

I am trying to run the uci command under a for loop like below:

for iface in `cat /etc/iface_list`
        var=$(uci -q get network.$
        if [ $var -eq 1 ] 2>/dev/null
                echo "status is UP"

But its not taking the uci command properly, and giving error like below:
-----debug log------

.auto'-q get 'network.bond0
+ var=
+ '[' -eq 1 ]

Any help is appreciated. Thanks


if [[ $var -eq 1 ]] 

There is nothing in var even. the problem is uci command is not getting executed properly.

The script is correct. Can you share the contents of /etc/iface_list as well as the output of uci show network | grep auto ?

You script executed fine for me and returned the value of auto for each interface that had it set. For all other interfaces an error was returned: uci: Entry not found.

Your /etc/iface_list file contains Windows newlines (\r\n) while Linux uses just line feeds (\n) as EOL designation.

This causes each word in your for loop to contain a trailing, invisible \r so you're not actually querying but network.bond0\ which causes $var to be always empty.

Solution: convert your /etc/iface_list file to UNIX line endings.


Thank you so much jow. That was a correct catch.
after converting the file for unix , it worked.
i was kinda puzzled for a few hours but thanks to you :slight_smile:

If your problem is solved, please consider marking this topic as [Solved]. See How to mark a topic as [Solved] for a short how-to.

1 Like