EVAL syntax problems


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting EVAL syntax problems
# 1  
Old 05-02-2012
EVAL syntax problems

Hi there

As part of a larger script I need to put the output of an ls into a variable which has an incremental number.

ie

Code:
nathan@nathan-Vostro-1700:~$ eval 'proc'$val='`ls -ld /proc/9467`'
nathan@nathan-Vostro-1700:~$ echo $proc0
dr-xr-xr-x 8 nathan nathan 0 2012-05-02 09:21 /proc/9467

However what I need is just the dtae and time stamp from the output, so of course out came awk

Code:
nathan@nathan-Vostro-1700:~$ eval 'proc'$val='`ls -ld /proc/9467 | awk 'print {$6,$7}' `'
-bash: unexpected EOF while looking for matching ``'
-bash: syntax error: unexpected end of file

I have trtied all sorts of ways but I can't get my syntax right Smilie

Help please Smilie

Last edited by Scrutinizer; 05-02-2012 at 07:04 AM.. Reason: code tags
# 2  
Old 05-02-2012
is your awk is correct ?

Code:
 
awk '{print $6,$7}'

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 05-02-2012
The awk was wrong. Try:
Code:
eval "proc$val=\"`ls -ld testdir|awk '{print $6,$7}'`\""

or without the backtickss:
Code:
eval "proc$val=\"$(ls -ld testdir|awk '{print $6,$7}')\""

This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 05-02-2012
Thank you that works a treat! very much appreciatted
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

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

4. Shell Programming and Scripting

Problems with variables syntax

Hi there I am really struggling :eek: to place a value in a variable with the following loop, having run out of ideas please can someone point me in the right direction? We first read two PIDs of a program (say calc) into an array, then we loop reading the details of those processes into a... (6 Replies)
Discussion started by: nathan.harris
6 Replies

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

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

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

8. Shell Programming and Scripting

sed - multi-line regex syntax eval puzzle

sed novice bashing away at this.... I am trying to build a sed script that will find the instances of "cn" that have more than one "DirXML" value on them.... see sample below: I am not having any luck with any variation that tries to find "DirXML.*\nDirXML.*". Isn't there a way to get sed to... (6 Replies)
Discussion started by: gosleddog
6 Replies

9. Shell Programming and Scripting

Problems with Syntax

I'm an experienced programmer that is new to shell scripting. I'm putting together a shell script that erases all files of a certain age. These files are in directories provided on lines of a file that is provided via command line argument and takes any errors(permissions, etc) and emails them to a... (3 Replies)
Discussion started by: drew2002
3 Replies

10. Shell Programming and Scripting

Problems with syntax in a loop (AWK)

Hi guys, I'm trying to loop through a number of files that is set by whatever is in a field. eg. The idea is to split FILELIST down into fields, it could contain 1 - 999 fields and it's bar delimited. I thought simple, count the number of fields in the field and then loop... (1 Reply)
Discussion started by: Peejay
1 Replies
Login or Register to Ask a Question