![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using variables created sequentially in a loop while still inside of the loop [bash] | DeCoTwc | Shell Programming and Scripting | 2 | 06-23-2009 05:59 PM |
| global variables and dynamic allocation | littleboyblu | High Level Programming | 3 | 04-09-2009 07:35 PM |
| dynamic variables | max_payne1234 | UNIX for Dummies Questions & Answers | 4 | 09-05-2008 04:10 AM |
| Dynamic update loop query on Sybase database | Alaeddin | Shell Programming and Scripting | 10 | 12-13-2007 06:26 AM |
| Dynamic variables within shell script | isingh786 | Shell Programming and Scripting | 2 | 01-25-2007 09:44 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Problem with dynamic variables outside the loop
Hi All, Shell is ksh I've given portion of the script here to explain the problem. It will accept 2 input parameters . Code:
in_file1=$1 in_file2=$2 outbound_dir=/home/outbound for i in 1 2 do eval file$i=$outbound_dir/\$in_file$i eval echo "filename is \$file$i" eval temp_file=$outbound_dir/\$in_file$i eval FILE$i_LINE_COUNT=`wc -l < $temp_file` eval echo "Total lines in file$i are \$FILE$i_LINE_COUNT" done echo "file1 name outside loop is $file1" echo "file1 count outside loop is $FILE1_LINE_COUNT" When i am displaying file1 and $FILE1_LINE_COUNT variables inside the loop its giving correct values. But ouside the loop getting correct value for only file1 variable not getting for $FILE1_LINE_COUNT variable. can you pls help me. Last edited by Franklin52; 08-21-2009 at 01:38 PM.. Reason: Adding code tags and reformat code |
|
||||
|
First off, please format your post so it is readable. Not reading your post very closely, but based on the last sentence, have a look at Counting items in variables, How come this works, However
|
|
||||
|
Better, please use the code tags for code. In any case, this has nothing to do with the loop specifically. Replace Code:
eval FILE$i_LINE_COUNT=`wc -l < $temp_file` with Code:
eval FILE${i}_LINE_COUNT=`wc -l < $temp_file`
You were assigning the word count output to $FILE since $i_LINE_COUNT was undefined. Surround the 'i' with curly braces to distinguish it from the rest of the line. |
|
||||
|
thanks for your reply....it works fine with curly braces.
eval file$i=$outbound_dir/\$in_file$i eval echo "filename is \$file$i" eval temp_file=$outbound_dir/\$in_file$i eval FILE${i}_LINE_COUNT=`wc -l < $temp_file` Can i use $file$i instead of $temp_file in the above line ?? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|