The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
String concatenation issue in ksh arvindcgi Shell Programming and Scripting 3 05-16-2008 08:57 AM
Searching for a string variable mattrix UNIX for Dummies Questions & Answers 2 03-04-2008 12:04 PM
string concatenation systemsb UNIX for Dummies Questions & Answers 7 04-04-2006 09:03 AM
parsing a string into variable Anubhav Shell Programming and Scripting 5 02-10-2006 09:02 AM
how to cut a string from a variable kjaisan UNIX for Dummies Questions & Answers 2 10-30-2003 09:13 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-18-2008
Registered User
 

Join Date: Oct 2007
Posts: 4
Arrow Help concatenation string and variable

Hello,
in my script i have this lines of code in a while cycle:

..
let j=i+1
t_prod_$i = `cat myfile.csv | grep world | cut -d ";" -f$j`
let i+=1
...

So if i try an echo $t_prod_$i at the end of the cycle i cannot see
the right value obtained by `cat myfile.csv | grep world | cut -d ";" -f
$j` but I receive an error:

./myscript.sh[17]: t_prod_1: not found.

how i should assign output of the command between ` ` to the variable
t_prod_$i (so i will have t_prod_1= ... t_prod_2=... )??

thanks for helping
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-18-2008
Registered User
 

Join Date: Jun 2006
Posts: 73
try

eval t_prod_$i = `cat myfile.csv | grep world | cut -d ";" -f$j`
Reply With Quote
  #3 (permalink)  
Old 02-18-2008
Registered User
 

Join Date: Oct 2007
Posts: 4
Quote:
Originally Posted by quintet View Post
try

eval t_prod_$i = `cat myfile.csv | grep world | cut -d ";" -f$j`

nothing get the same error...

i'm using Posix Shell under Hp-UX
Reply With Quote
  #4 (permalink)  
Old 02-18-2008
Registered User
 

Join Date: Jun 2006
Posts: 73
hi,

can u try removing the space bewteen t_prod_$i and =

eval t_prod_$i= `cat myfile.csv | grep world | cut -d ";" -f$j`
Reply With Quote
  #5 (permalink)  
Old 02-18-2008
Registered User
 

Join Date: Oct 2007
Posts: 4
Quote:
Originally Posted by quintet View Post
hi,

can u try removing the space bewteen t_prod_$i and =

eval t_prod_$i= `cat myfile.csv | grep world | cut -d ";" -f$j`
nothing

if I put standard variable name, like t_prod_1= ... i have no problem, maybe i cannot create dinamically variable names?
Reply With Quote
  #6 (permalink)  
Old 02-18-2008
Registered User
 

Join Date: Oct 2007
Posts: 4
need a way to build variable in this manner:

variable_$i

where i goes from 1 to 5 for example...

and then print them on screen with echo $variable_$i


which is the best way to do this?
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0