|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
echoing two variables in one statement
I have the following
-------------------- foreach var (STO SNY WKF) set ta = 5 end --------- How can I echo both variables at the same time. Something to the effect of echo ${$var}ta But this doesn't work. Seems like it would. Thanks. |
| Sponsored Links |
|
|
|
|||
|
Yeah I didn't phrase my question the way I wanted to. Let me try again.
Given the following: ---------------------- foreach var (t v w) grep $var ./file > ./newfile set ${var}temp = `awk '{print $2}' ./newfile` now this is where I need help how can I echo each variable with only one echo statement, essentially, do: echo $ttemp $vtemp $wtemp But doing this with alot of variables, creates a long script, and is not very efficient. I've tried the following echo ${$var}temp, this doesn't work end Hopefully this makes more sense than before. Thanks in advance. |
|
|||
|
I may not have understood the problem correctly - and it looks a bit artificial, not homework is it? - but it looks as if you trying to set variables where the variable name is created from the loop variable (t, v, w) and 'tmp' (i.e. ttmp, vtmp, wtmp)? If so then you need to use 'eval' to do the substitutions for the variable name before assigning it a value. Something like: Code:
for var in t v w do
grep $var ./file > ./newfile
eval ${var}tmp=`awk '{print $2}' ./newfile`
eval print ${var}tmp set
doneNote that this will fail if the 'grep' finds more than one matching line If I've got hold of the wrong end of the twig then try a more detailed explanation of what you are trying to achieve cheers Steve |
|
|||
|
Quote:
thanks for the help, don't worry it isn't homework. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| I can't seem to pass variables properly into a nawk statement | DeCoTwc | Shell Programming and Scripting | 6 | 03-30-2008 03:07 PM |
| Echoing | Okema | Shell Programming and Scripting | 3 | 03-12-2008 11:33 PM |
| echo not echoing correctly | shorty | UNIX for Dummies Questions & Answers | 3 | 09-25-2006 05:45 PM |
| Variables within a sed statement | sirtrancealot | Shell Programming and Scripting | 5 | 07-18-2006 05:41 PM |
| How can I put wildcards in an if statement that uses variables? | LordJezo | UNIX for Dummies Questions & Answers | 3 | 06-14-2004 01:27 PM |