different way to echo varibles...help


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers different way to echo varibles...help
# 1  
Old 01-05-2006
different way to echo varibles...help

Given the following loop:

foreach id (DB4 GH4 CD4)

and the previously defined variables:

DB4sf DB4sfk DB4pp
GH4sf GH4sfk GH4pp
CD4sf CD4sfk CD4pp

how do i echo all of these variables using a one line command in the for loop. If it was a script, and assuming the previously mentioned variables, it would look like this if it worked. Smilie

#! /bin/csh
foreach id (DB4 GH4 CD4)

echo $idsf $idsfk $idpp
end

exit 0
# 2  
Old 01-05-2006
Try This

#! /bin/csh
foreach id (DB4 GH4 CD4)

echo ${id}sf ${id}sfk ${id}pp
end

exit 0

Thanks ,
Ashok
# 3  
Old 01-05-2006
Quote:
Originally Posted by akrathi
Try This

#! /bin/csh
foreach id (DB4 GH4 CD4)

echo ${id}sf ${id}sfk ${id}pp
end

exit 0

Thanks ,
Ashok
Doing this displays:
DB4sf DB4sfk DB4pp, then likewise for each remaining word. Anyone else have an idea? I know the variable has been set, because if i just echo the actual variable name i get the value.
# 4  
Old 01-05-2006
Can you give an examples of the output you want ?
# 5  
Old 01-05-2006
Yup, the output will be a string then some numerical values, such as


DB4 4 0 1 4

The first field is a site id, the next four fields are just that numbers.

So the value is already set in a previous portion of my script, but since there are over 30 sites I have to do this for, I am trying to display it using one line, hence the:

echo $id $idsf $idsfk $idpp

DB4sf has a value assinged to it, i just need to display it using a variable. Using the curly braces, just displays DB4sf rather than the numerical value. Hope this helps, thanks for looking at this for me.
# 6  
Old 01-05-2006
I think that csh has eval, so try this:

#! /bin/csh
foreach id (DB4 GH4 CD4)

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

exit 0
# 7  
Old 01-05-2006
hey that worked awesome, thanks a lot.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need Help Setting Path and Environment Varibles

Hello all, I have a Mac OS X (10.7), and I need to set environment variables and paths for some programs I will be running. I have followed instructions and searched the Web for where to do this, but I can't seem to find an answer. I have tried using the VIM editor to write them into my .login,... (2 Replies)
Discussion started by: Tyler_92
2 Replies

2. Shell Programming and Scripting

Passing varibles as a string argument ?

For example test.sh: test="teststring" cmd=$1 $cmd For some reason I'm NOT seeing "teststring" when I type: ./test.sh "echo $test" Any ideas on how to get around this? I've tried commands like: ./test.sh "echo $($test)" ./test.sh "echo '$test'" And many variations to no... (6 Replies)
Discussion started by: secops
6 Replies

3. Shell Programming and Scripting

With that logic this echoes "echo". Question about echo!

echo `echo ` doesn't echoes anything. And it's logic. But echo `echo `echo ` ` does echoes "echo". What's the logic of it? the `echo `echo ` inside of the whole (first) echo, echoes nothing, so the first echo have to echo nothing but echoes "echo" (too much echoing :P):o (2 Replies)
Discussion started by: hakermania
2 Replies

4. Shell Programming and Scripting

Multiple varibles in file

Working on a way to speed up my script output. I have a multiline file that I pull each line as a variable and post it on a webpage. It needs some help as it works but slow. I think I have too many cat, grep and sed going on but don't know what would work better. #!/bin/sh... (5 Replies)
Discussion started by: numele
5 Replies

5. 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

6. Shell Programming and Scripting

Difference between using "echo" builtin and /bin/echo

So in my shell i execute: { while true; do echo string; sleep 1; done } | read line This waits one second and returns. But { while true; do /bin/echo string; sleep 1; done } | read line continues to run, and doesn't stop until i kill it explicitly. I have tried this in bash as well as zsh,... (2 Replies)
Discussion started by: ulidtko
2 Replies

7. Shell Programming and Scripting

split varibles and store fields into shell varible array

I need to split a long varible which is a whole line read from a file into fields and store them in an array, the fields are delimited by pipe and a field may contain white spaces. I tried the following concept test and it has problem with field 5 which contain a space, appearently so because... (3 Replies)
Discussion started by: gratus
3 Replies

8. UNIX for Dummies Questions & Answers

How to create ENV varibles

Hi, I want create env variable for "/ramakrsihna/scripts" help me on this. (1 Reply)
Discussion started by: koti_rama
1 Replies

9. Shell Programming and Scripting

Dynamic Varibles problem

All, Any chance someone could help me with this.... The script is reading from a file and for every line of input to the loop I am trying to assign a new varible. When i run the script I get the below errors. I have come to a bit of a dead end so any pointers/help would be very much... (1 Reply)
Discussion started by: oconnon2
1 Replies

10. UNIX for Dummies Questions & Answers

environmental varibles

flavor -- AIX 4.2.1 I am putting together some HTML pages, some of which contain forms. The problem pops up when I attempt to pass variables (from the forms) from one HTML page to a cgi-like page created using ksh. I have used the $1 - $9 vars, but they do not work with the passing. With... (1 Reply)
Discussion started by: Xiix
1 Replies
Login or Register to Ask a Question