The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
assigning date value to a variable mansoorbabu Shell Programming and Scripting 1 06-13-2008 07:35 AM
Assigning Value of variable janemary.a Shell Programming and Scripting 2 05-11-2007 05:53 AM
Assigning a value to variable sirtrancealot Shell Programming and Scripting 3 07-15-2006 03:07 PM
assigning variable value using echo shellburger Shell Programming and Scripting 2 07-11-2005 11:52 AM
assigning a variable containing hostname esham Shell Programming and Scripting 4 03-08-2005 12:00 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-21-2008
kaushikraman kaushikraman is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 13
Assigning evaluated expression to a variable

Hello,

Could you please let me know what is the problem here..
28:var1="SERVER_$j"
29:eval $var1=`grep "^DBSERVER=" "$i" |cut -d"=" -f2`

i get this error:

syntax error at line 29 : `|' unexpected

Thanks for your quick response..This is urgent..pls..

Regards
Kaushik
  #2 (permalink)  
Old 07-21-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,259
Sorry, have no working solution yet - can't delete my post, sorry

Last edited by zaxxon; 07-21-2008 at 09:43 AM..
  #3 (permalink)  
Old 07-21-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,259
That should hopefully work - tested it on some similar example.

Code:
var1="SERVER_$j"
TMP_VAR="`grep "^DBSERVER=" "$i" |cut -d"=" -f2`"
eval ${var1}="${TMP_VAR}"
  #4 (permalink)  
Old 07-22-2008
kaushikraman kaushikraman is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 13
It still does not work...Does it have to do something with the filename being conatined in the variable i?
  #5 (permalink)  
Old 07-22-2008
Vi-Curious Vi-Curious is offline
Registered User
  
 

Join Date: Jul 2008
Location: Texas
Posts: 129
Code:
 
#!/usr/bin/bash
i=test.txt
j=B10
var1=SERVER_"$j"
echo "DBSERVER = $var1"
eval var1=`grep "^DBSERVER=" "$i" | cut -d"=" -f2`
echo "DBSERVER = $var1"
With file test.txt containing:
Code:
 
line 1
 DBSERVER=SERVER_XXX
line 3
DBSERVER=SERVER_A1
line 5
Produces the following when run:
Code:
 
HOSTNAME:> test.sh
DBSERVER = SERVER_B10
DBSERVER = SERVER_A1
  #6 (permalink)  
Old 07-22-2008
kaushikraman kaushikraman is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 13
Thanks folks..Problem got resolved..there was a mismatching '`' above the mentioned lines of code which was causing the problem..

Thank you...
Regards
Kaushik
Closed Thread

Bookmarks

Tags
assignment, bash, bash eval, cut, eval, grep, variable

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0