[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Strange variable asignement in bash script



If what you are trying to to is to create a bunch of variables, here's one way:

TMPFILE=/tmp/xxx
TEST="service1 service2 service3"
HOSTS="server1.mynet server2.mynet server3.mynet"

touch $TMPFILE
for I in $TEST
do
  for J in $HOSTS
  do
    ...
    echo "${I}.${J}=\"some value\"" >>$TMPFILE
  done
done

. $TMPFILE
rm -f $TMPFILE

-- 
Peter A. Dumpert
Innovative Computer Services, LLC
www.innovativebusiness.net

Quoting Juanillo <flipaxos-listas@yahoo.es>:

> >Hello,
> 
> >> Content-Type: text/plain;
> >>   charset="gb2312"
> 
> >What is that charset ??
> 
> >Please do not hijack an existing thread with a new one that
> >has nothing to do with.
> Sorry I don't know what happened
> 
> >Juan Sierra Pons a écrit :
> >> problem I can't create a variable like this $TEST.$HOST in the left side
> of 
> =
> 
> >Well, seems like bash doesn't like dots in its variable name :
> >eh@bubulle:~$ a=1
> >eh@bubulle:~$ a.b=1
> >bash: a.b=1: command not found
> 
> >Use underscores in place of dots ?
> 
> the problem isn't the dots in a variable name, I also tried:
> 
> juan@elsotanillo:~$ $TEST$HOSTS="some value"
> bash: popmaquina1=some value: command not found
> 
> juan@elsotanillo:~$ `echo $TEST$HOSTS`="some value"
> bash: popmaquina1=some value: command not found
> 
> juan@elsotanillo:~$ `echo ${TEST}${HOSTS}`="some value"
> bash: popmaquina1=some value: command not found
> 
> juan@elsotanillo:~$ ${TEST}${HOSTS}="some value"
> bash: popmaquina1=some value: command not found
> 
> bash: maquina1=some value: command not found
> juan@elsotanillo:~$ "$TEST_$HOSTS"="some value"
> 
> bash: maquina1=some value: command not found
> juan@elsotanillo:~$ "$TEST_$HOSTS"="some value"
> 
> I think It can't be done.... It's impossible declare a variable with $ on the
> 
> left side of = . Am i wrong?
> 
> Anyone knows another method to do that i want?
> 
> Thanks a lot
> 
> -- 
> ----------------------------------------------------------------------------
> Usuario Linux Registrado: 257202
> http://perso.wanadoo.es/elsotanillo (en construcción)
> ----------------------------------------------------------------------------
> 
> >-- 
> >Emmanuel Halbwachs              Labo. de Photonique et Nanostructures
> >tel      : (+33)1 69 63 61 34                             CNRS UPR 20
> >fax      : (+33)1 69 63 60 06       Route de Nozay F 91460 Marcoussis
> 
> 
> -- 
> To UNSUBSCRIBE, email to debian-isp-REQUEST@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact
> listmaster@lists.debian.org
> 
> 
> 



Reply to: