Originally Posted by luvshines
Thanks for the reply, but the problem still stands.
Well actually the problem which i have described is only subset of the whole program.
The actual code is
echo "create set_$i"
echo "create set_$i server_`expr $server % 3 + 1`:$path`expr $pathvar % 5`"
echo "mount set_$i ROOT:/dir_$i"
((server = server + 1))
((pathvar = pathvar + 1))
So i can't that for loop which you mentioned. Any other solution ??
I think maybe you're looking for something more like this:
path=(/etc /usr /bin /boot /tmp)
setname=set_$((server * 5 + pathvar))
dirname="ROOT:/dir_$((server * 5 + pathvar))"
echo "create $setname"
echo "create $setname $servername:$pathname"
echo "mount $setname $dirname"
That yields this:
create set_0 server_0:/etc
mount set_0 ROOT:/dir_0
create set_1 server_0:/usr
mount set_1 ROOT:/dir_1
create set_2 server_0:/bin
mount set_2 ROOT:/dir_2
create set_3 server_0:/boot
mount set_3 ROOT:/dir_3
create set_4 server_0:/tmp
mount set_4 ROOT:/dir_4
create set_5 server_1:/etc
mount set_5 ROOT:/dir_5
create set_6 server_1:/usr
mount set_6 ROOT:/dir_6
create set_7 server_1:/bin
mount set_7 ROOT:/dir_7
create set_8 server_1:/boot
mount set_8 ROOT:/dir_8
create set_9 server_1:/tmp
mount set_9 ROOT:/dir_9
I broke the variables out of the echo statements to help clarify things a bit. I also rearranged the logic a little, because I'm not sure the logic you had was going to do what you wanted. MOD 5 on a variable that is always a multiple of 10 will always yield 0.
$((expression)) is a different way of doing `expr expression`.
At any rate, I think the heart of the problem you are having is that you are trying to emulate using an array. Since BASH has array variables, it is far easier (and cleaner) to just use an array.
Basically, you can define array variables in bash with either
variable=(value1 value2 value3 ...)
and you get the values back with
You can see http://tldp.org/LDP/Bash-Beginners-G...ect_10_02.html
for a much more in depth description of how to use arrays in bash.