Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!uunet!wang!bu-tyng!bu-tyng.bu.edu!farnham From: farnham@bu-tyng.bu.edu (Dave Farnham) Newsgroups: comp.unix.questions Subject: Help with functions and eval Message-ID: <3216@bu-tyng.bu.edu> Date: 22 Feb 90 02:04:27 GMT Sender: farnham@bu-tyng.bu.edu Distribution: usa Organization: Boston University Corprate Education Center, Tyngsboro MA Lines: 42 I am attempting to do the following in the Bourne shell. 1. Perform a 'read' on a variable in a function through the position parameters. 2. Loop while the variable contains a NULL string (force the user to input something). The following code works, but I had to use a temporary variable. I tried to use 'eval' in my test condition and I think the root of my problems is a lack of understanding of what exactly 'eval' does and how it works. I know there are probably a hundred ways to re-write my function, rather than "use this it's better". I would really appreciate a re-write with an explanation. Thanks Dave ------------------ #!/bin/sh fun() { tmp="" while [ -z "$tmp" ] # I tried to use eval here on "\$$1" do echo "Enter $2 " # Enter "text string" read `echo $1` # Read into a variable eval tmp="\$$1" # tmp=$variable done } fun var1 name fun var2 age echo $var1 echo $var2 ------------------ Dave Farnham ( ...!uunet!wang!bu-tyng!farnham , farnham@bu-tyng.bu.edu ) Tel: (508) 649-9731 Fax: (508) 649-6926