Beginner Shell programmer needs HELP (belonged on comp.unix.shell)

Beginner Shell programmer needs HELP (belonged on comp.unix.shell)

Post by Peter Alla » Tue, 23 Apr 1996 04:00:00



Jeff,

Your post was:

  >   I have a simple script that reads in two files that contain a list of variables
  >   and a list of values to assign to those variables. The script sorts them just
  >   fine. But where I run into a problem is in assigning the values to the
  >   variables. Here is the script
  >  
  >   #!/bin/sh
  >   OLD_PARAM=`cat $HOME/.genpad.prm | cut -d " " -f 3`
  >   ALL_VARS=`cat $HOME/.genpad.var | cut -d " " -f 2`
  >   COUNTA=1
  >   COUNTB=1
  >   for SET in `echo $ALL_VARS`
  >   do
  >   echo $COUNTA
  >   `echo $ALL_VARS | cut -d " " -f $COUNTA`=`echo $OLD_PARAM | cut -d "
  >   COUNTA=`expr $COUNTA + 1`
  >   COUNTB=`expr $COUNTB + 1`
  >   done
  >  
  >   I get the error "./genpad: G9_OBD2_IP=YES: not found"
  >   where the G9 is my variable and YES is the value I want assigned
  >   any suggestions would be greatly appreciated.
  >  
  >   Jeff S.

Try this interactively:
sh                  to start a Bourne shell
name=PIGLET         set a variable name
$name=EXPERIMENT     fails, right ?
exit

You can execute shell variable values  ( nextcommand=ls ) but
not set them as variables.

Since in this case you were reading them from a file why not
put VAR1=VAL1 etc on lines in one file and then execute that ?

For the Bourne shell the command is "."  
. set_my_vars_file

or in the C-shell it is "source".

And nawk has associative arrays that I use at times like this.

Future shell (as opposed to C)  questions to comp.unix shell please.
Hope this helps.