Hello
Is it possible to use arrays in the shell scripts?
Yes, it's easy, I use some array's in SolGet, my solar monitoring script.
For instance, i have a file where some values are saved. I get them into an array with cat:
updating values can be done by:Code:array1=(`cat $file`)
writing back my array to file:Code:array1[2]=$value
If you're interested, my full script is available at http://solget.sourceforge.netCode:echo ${array1[0]} ${array1[1]} ${array1[2]} ${array1[3]} ${array1[4]} > $file
(I installed bash on my asus)
Solar inverter monitoring with Asus wl500gx http://solar.reinieren.net (dutch)
Thanks for replies. So I have to instal bash on my Asus? (in sh scripts I got such error ./test: ./test: 5: Syntax error: "(" unexpected)
Bash will work for sure.
will do the trick.Code:ipkg install bash
If you change your passwd file, you can set bash as default shell.
Keep in mind that bash will be installed into opt, which will be an external drive most of the times. So if that drive is not available, and you have only one account with bash as default shell, you can run into a lock out situation.
I took the risk, I run bash as default shell. (with a good backup scenario )
You also have to create a file called /etc/shells which contains all possible shells, to let ssh accept the shells.
My file contains:
Don't forget to start your scripts with:Code:/bin/sh /opt/bin/bash
If you want to run the script in bashCode:#! /opt/bin/bash
Solar inverter monitoring with Asus wl500gx http://solar.reinieren.net (dutch)
I hope no one gets upset that I revive a 3 years old thread, but I found this useful.
I installed bash and managed to use arrays, but I need something like a pointer for this code:
Basically I need to cycle trough tokens from 2 to 25 of a line in a file ($data is path to a file).Code:for i in `seq 2 25`; do var=`expr $i - 2` h[$var]=`awk '/D*/{print(<pointer>)}' "$data"` echo ${h[var]} done
<pointer> has to be something like value of the variable with the name equal to the value of variable "i" (ie ${$i} )