use of eval n grep


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers use of eval n grep
# 1  
Old 02-15-2005
use of eval n grep

1.
on prompt,i wrote
eval echo \$p[12]

ive defined p1 n p12 as variables n i wanted their values to be printed on the screen but this did not happen.
how else can i acheive the same result with eval ??


2.
when i write : grep "asb*[Mn]" a1.txt , the search pattern's metacharacters, by virtue of being enclosed within(" "), are not intrpreted by the shell.
who then interprets it before the kernel executes the command?
# 2  
Old 02-15-2005
For your first question, you can do this a couple of ways, two of which are below....
Code:
for i in 1 2 3 4 5 6 7 8 9 10 11 12
do
  eval echo \$p$i
done

or
Code:
i=1
while [ "$i" -le "12" ]; do
  eval echo \$p$i
  (( i = i + 1 ))
done

There are many other ways of doing this too....

Cheers
ZB
# 3  
Old 02-16-2005
thanks for the alternatives..but a few doubts follow
(n i must sincerely thank u guys for the help)

1.isnt the way i gave the command ie :
eval echo \$p[12]

alright? i believe this will be expanded, by the shell to p1 and p2 so in effect, after the shell has worked on the command it will look like :
eval echo \$p1 \$p2

but obviously this is not what the shell is doing,in fact it complains that :
parameter p not set

so how is the shell interpreting the command?why arent the metacharacters "[" and "]" being used to derive the meaning i take it to be.

2.
can u plz also look into the 2nd question from my first post
# 4  
Old 02-17-2005
Please read the rules - I deleted your new thread (eval) due to the fact you are asking the same question as in this post. Keep your questions in the same thread as you did here and do not try to 'bump' to get a response.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Eval set -- and more

Hello everyone, I am taking a course on Lynda and they show this code below. I didn't fully understand some parts. Please see the questions within the code. Thank you for your input and time. Regards, function usage { echo Options are -r -h -b -x --branch --version --help --exclude... (9 Replies)
Discussion started by: mohca2020
9 Replies

2. Shell Programming and Scripting

Eval in awk

Hi I am trying to remove duplicates on keys in a file and so far the below seems to work sort -t\| -k2,4 input.txt| awk -F'|' '{if (NR==1) print $0} {x=$2 $3 $4} NR>1 {if ($2 $3 $4 != y) {print $0}} {y=x}' and now I want to pass comma seperated column number list to the script and use... (3 Replies)
Discussion started by: zulfi123786
3 Replies

3. Shell Programming and Scripting

Eval

thank you (35 Replies)
Discussion started by: ratnalein88
35 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... (13 Replies)
Discussion started by: vivek d r
13 Replies

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

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

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

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

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

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