reading value of concatenation with ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting reading value of concatenation with ksh
# 1  
Old 10-17-2010
reading value of concatenation with ksh

hello all, I am trying to read the value of a concatenation, the following code is displaying
$word1
$word2
I want to display
village
home

Thanks

for (( i=1; i<=2; i++ ))
do

word1='village'
word2='home'

con="$"word"$i"
echo $con

done
# 2  
Old 10-17-2010
Code:
word1='village'
word2='home'
echo "$word1 $word2"

If you want to deal with an array , use brackets []
# 3  
Old 10-17-2010
I will be calling a function inside the loop "for" and I want to pass word"i" as a parameter so I need to make it work the way I displayed it in the code as con="$"word"$i"

Thanks
# 4  
Old 10-17-2010
Code:
eval con=\$word$i

# 5  
Old 10-18-2010
Thanks a lot.
# 6  
Old 10-18-2010
bash code:
  1. for (( i=1; i<=2; i++ ))
  2. do
  3.    word1='village'
  4.    word2='home'
  5.    con=word"$i" # Note that ther's no "$" in front
  6.    echo "$con = '${!con}'"  # Note the ${!<VARIABLE>} to expand to the content of <VARIABLE>.
  7. done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Reading file and exclude in ksh

I have a text file containing some file names. And I've a directory containing files with different name. I want to do some operaration (deleting) on the files which are NOT listed on the text file. Im using KSH. PLEASE HELP !!!!! Urgent Help!!!!! (2 Replies)
Discussion started by: maheshbabu
2 Replies

2. Shell Programming and Scripting

Reading xml tags from ksh script

Hi, I have an XMl file, below is sample: <TRANSFORMATION DESCRIPTION ="Created by:- " NAME ="LKP_FT_T_FILEK" OBJECTVERSION ="1" REUSABLE ="YES" TYPE ="Lookup Procedure" VERSIONNUMBER ="1"> </TRANSFORMATION> I need to read the tag, and if the tag is TRANSORMATION, i want to check the Type... (6 Replies)
Discussion started by: kedar_laveti
6 Replies

3. Shell Programming and Scripting

Reading the contents of the file and splitting using ksh

We're using a ksh script for installing one product. I've another config file, I'd need to read this configuration file from my main script Content of the Configuration file:... (2 Replies)
Discussion started by: bittu129
2 Replies

4. Shell Programming and Scripting

Problem reading into Variable using KSH

hi all, i create 1 file.txt and inside it contain : file1 file2 file3 file 4 then output that i want in my script: $1=file1 $2=file2 $3=file3 $4=file4 but,when write in ksh script with: while read folder set - $( echo ${folder} ) i=1 while (($i <= $#)) do ... (2 Replies)
Discussion started by: proghack
2 Replies

5. Shell Programming and Scripting

ksh questions - Reading columns and lines on unix

1-) For the command below, I want to read second column: 32751. How will I get it ? $ ps -ef|grep deneme U00 32751 22745 0 16:30 pts/1 00:00:00 ksh deneme U00 32762 32132 0 16:30 pts/2 00:00:00 grep deneme 2-) For the command below, how will I read all lines line by line? For... (1 Reply)
Discussion started by: senem
1 Replies

6. Shell Programming and Scripting

Reading Numerical Binary Data using KSH

Hi, I've searched and couldn't find anyone else with this problem. Is there anyway (preferably using ksh - but other script languages would do) that I can read in binary float data into a text file. The data (arrays from various stages of radar processing) comes in various formats, but mainly... (3 Replies)
Discussion started by: Jonny2Vests
3 Replies

7. Shell Programming and Scripting

reading from file in ksh

hi, it seems i can read using cat file | while read line but when i tried reading using while read line < myfile then the last line kept on being returned why? thanks (2 Replies)
Discussion started by: JamesByars
2 Replies

8. Shell Programming and Scripting

String concatenation issue in ksh

Hello All, I'm tryying to concatenate string and variables value in ksh, but i'm unable to do it, can someone please help in rectifying my error, here is the code i have written, #!/usr/bin/ksh -x cat $1 | while read fileline do val1= echo $fileline | awk -F, '{print $1}' val2= echo... (3 Replies)
Discussion started by: arvindcgi
3 Replies

9. Shell Programming and Scripting

reading lines in pairs from file in ksh

I need to read pairs of lines from a file and compare them. We can assume that the number of lines in the file is even. Can i do it in korn shell? (4 Replies)
Discussion started by: ytokar
4 Replies

10. Shell Programming and Scripting

Help reading an input file in KSH

First I' d like to say you guys are awesome. :) I have a word document that I cut and paste into Textpad and it removed all the fancy formatting which is fine with me. I WinScp'd it to the box and and called it inputfile.txt. Opened it in vi and don't see any special characters or stuff that... (2 Replies)
Discussion started by: zilla30066
2 Replies
Login or Register to Ask a Question