Bash Variable Naming Question?
I'm writing a script for asterisk to monitor trunk failure, i do a loop for every trunk it got nad would like to name variable like server1=, server2= naming the server upgoing as the trunk is. here is the scripts:
Code:
#!/bin/bash Code:
./test.sh: line 45: server1=74.63.41.218: command not found |
Code:
server"$COUNT"="$A" Code:
server[$COUNT]="$A" BTW: I see two different spellings, server, and serveur. Are these supposed to be the same? Also, you should quote your echo strings. Code:
echo "Serveur: $serveur" |
ok ... while not easy it is actually possible to have dynamic variables but its fiddly and you may need to be careful on how you go about it.
The general scenario is this: 1. Create variable names using eval 2. Assign the created variable name to another variable 3. Access data using indirect references Code:
#!/bin/bash |
Code:
Code: Code:
#Checking number if IAX2 Peer marked as trunk. |
That is because you used a pipe into the loop. This cause a subshell and once returned from any variables created inside are lost.
Dpepnding on what is stored in iax2_peer you could try a for in loop or maybe a here document on your while loop |
You can also use a here string instead of a pipe.
Code:
while read line; do |
Damn ... string not document ... that was what I was thinking of .. thanks David :0
|
Actually, it is possible to use a here document as well. It's just not as clean looking ;)
Code:
while read line; do |
All times are GMT -5. The time now is 04:29 PM. |