using eval w/ echo


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using eval w/ echo
# 1  
Old 01-16-2006
using eval w/ echo

My script has the following for loop in it.

foreach id (CLKM4 DGTM4 GNNM4)

eval echo $id \$${id}sf \$${id}sfk

end


so "id" is a variable defined in the loop, and "idsf" and "idsfk" are variables defined in another part of the script, they return values of 0 or more. The problem i'm having is putting spaces in between the returned values. It seems that eval doesn't recognize spaces like " ", Is their a way I can't echo these same variables w/o using eval.
# 2  
Old 01-17-2006
This works for me, if I understand your requirements correctly....

Consider the following:
Code:
> set CLKM4sf="one"
> set CLKM4sfk="also_one"
> set DGTM4sf="two"
> set DGTM4sfk="also_two"
> set GNNM4sf="three"
> set GNNM4sfk="also_three"
> foreach id ( CLKM4 DGTM4 GNNM4 )
foreach?   eval echo $id \$${id}sf \$${id}sfk
foreach? end
CLKM4 one also_one
DGTM4 two also_two
GNNM4 three also_three
>

I assume that that is your desired output?

If it doesn't work like this for you, please post your OS version and shell version, this was tested on
Code:
> tcsh --version
tcsh 6.13.00 (Astron) 2004-05-19 (i386-intel-OpenBSD) options 8b,nls,al,kan,sm,rh,nd,color,dspm,filec
> uname -a
OpenBSD somehost 3.8 GENERIC#0 i386

Cheers
ZB
# 3  
Old 01-17-2006
Well I'm not having a problem displaying the data. I just need there to be spaces in between the last two fields. My loop works fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

Echo eval xargs and other siblings

It always seemed to me that these utils are siblings. All they do are that substitute values for variables, rearrange the parameters, and confuse the input with the output. :) I tried to display their main signature in table together. To show their similarities (3 Replies)
Discussion started by: nezabudka
3 Replies

2. Shell Programming and Scripting

Eval

thank you (35 Replies)
Discussion started by: ratnalein88
35 Replies

3. Shell Programming and Scripting

Error in eval eval command to print html tags

anyone has any info on why this is complaining??? vivek@vivek-c5e55ef2e ~/TAC $ zoneCounter=1 vivek@vivek-c5e55ef2e ~/TAC $ optUsage1=23% vivek@vivek-c5e55ef2e ~/TAC $ eval eval echo "<th>Zone $zoneCounter </th><th align=\"left\"> \$optUsage$zoneCounter </th>" -bash: syntax error... (13 Replies)
Discussion started by: vivek d r
13 Replies

4. Shell Programming and Scripting

Error in eval eval command to print html tags

anyone has any info on why this is complaining??? vivek@vivek-c5e55ef2e ~/TAC $ zoneCounter=1 vivek@vivek-c5e55ef2e ~/TAC $ optUsage1=23% vivek@vivek-c5e55ef2e ~/TAC $ eval eval echo "<th>Zone $zoneCounter </th><th align=\"left\"> \$optUsage$zoneCounter </th>" -bash: syntax error... (1 Reply)
Discussion started by: vivek d r
1 Replies

5. Shell Programming and Scripting

Help on eval please

Hello All, Since my variables are nested I use eval to populate the data. I have an ambiguity here when eval is used along with & say I have the below variable url="www.unix.com" , this come from function call as argument. I want to take this into another variable say... (6 Replies)
Discussion started by: sathyaonnuix
6 Replies

6. Shell Programming and Scripting

Strange result of eval, how does eval really work with ssh?

Hi all, some small script with eval turned me to crazy. my OS is linux Linux s10-1310 2.6.16.53-0.8.PTF.434477.3.TDC.0-smp #1 SMP Fri Aug 31 06:07:27 PDT 2007 x86_64 x86_64 x86_64 GNU/Linux below script works well #!/bin/bash eval ssh remotehost date eval ssh remotehost ls below... (1 Reply)
Discussion started by: summer_cherry
1 Replies

7. Shell Programming and Scripting

eval

hi all, Am trying to add some code to a ksh script and i dont understand how an eval function is used : _var=$1 _conceal=$2 eval _val=\$${_var} can someone shed some light on what the eval function in the above context means/does ?? thanks. (4 Replies)
Discussion started by: cesarNZ
4 Replies

8. Shell Programming and Scripting

eval help

I am trying to expand the variable $user in my alias command and tried several variations of eval but can't seem to get it to work. The end result should be either: oracle_user='sudo su - oracle ' or oracle_user='sudo su - oracle1 ' user=$(grep '^oracle:' /etc/passwd | cut... (5 Replies)
Discussion started by: BeefStu
5 Replies

9. UNIX for Dummies Questions & Answers

How to correctly use an echo inside an echo?

Bit of a weird one i suppose, i want to use an echo inside an echo... For example... i have a script that i want to use to take users input and create another script. Inside this script it creates it also needs to use echos... echo "echo "hello"" >$file echo "echo "goodbye"" >$file ... (3 Replies)
Discussion started by: mokachoka
3 Replies

10. Shell Programming and Scripting

EVal

Hi All, I'm running some encrypted data through a script I wrote. In order to do this, I'm using eval to resolve some of my variables. At the moment, when I use eval to resolve, it strips out some of my encrypted values, and totally drops some others. For example if I have the value ab1"3 it drops... (1 Reply)
Discussion started by: Khoomfire
1 Replies
Login or Register to Ask a Question