Beginner Shell programmer needs HELP

Beginner Shell programmer needs HELP

Post by Jef » Sat, 20 Apr 1996 04:00:00



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.

 
 
 

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

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.


2. TCP/IP via PrinterPort???

3. Need beginners book or location of tutorial on shell scripts

4. Help w/xrn6-17

5. Man pages for mount

6. Learning Kourne Shell - need a good beginner's book?

7. Shell Lisp ?

8. beginner shell scripting help

9. Whats a good book for the beginner linux programmer?

10. C Shell Programmers - Help!

11. Korn shell help with remote shell needed!

12. (newbie) Shell programmers plsss help me..