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 > 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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
comparing 2 files using nested for loop vadharah Shell Programming and Scripting 0 03-01-2008 04:32 AM
Nested loop not running using cronjob bihani4u Shell Programming and Scripting 9 09-26-2007 12:19 PM
Variable in While Loop Nested If geass Shell Programming and Scripting 6 03-26-2007 07:09 PM
Nested while read line loop Rakker Shell Programming and Scripting 7 06-24-2005 08:42 AM
nested loop chinog Shell Programming and Scripting 5 04-20-2005 11:45 AM

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

Join Date: Apr 2008
Posts: 18
nested loop problem

Please see the following script.

basic="a b c"
advance="d e f"

A="basic advance"

for g in $A
do
echo $g
done

The result would be obviously
basic
advance

I want to ask how can i get the following result using $A in for loop
a
b
c
d
e
f
  #2 (permalink)  
Old 07-04-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
Code:
basic="a b c"
advance="d e f"
A="${basic} ${advance}"
for g in $A; do
     echo $g
done
  #3 (permalink)  
Old 07-04-2008
mmunir mmunir is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 18
Thanks for reply!

The problem is that

The following statement has already been defined in a file and i cannot change it.

A="basic advance"

To change it into your style, i would do

A=`echo $A | sed -e s/' '/'} \${'/g`
A="\${${A}"

but when i run
echo $A

i get:

${basic} ${advance}

which is not the desired result
  #4 (permalink)  
Old 07-04-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
Code:
root@isau02:/data/tmp/testfeld> cat weekend.ksh
basic="a b c"
advance="d e f"
A="basic advance"

for ele in ${A}; do
        eval echo $`echo $ele`
done |\
tr -s " " "\n"

exit 0
root@isau02:/data/tmp/testfeld> ./weekend.ksh
a
b
c
d
e
f
  #5 (permalink)  
Old 07-04-2008
namishtiwari namishtiwari is offline Forum Advisor  
Registered User
  
 

Join Date: Aug 2007
Location: Bangalore
Posts: 377
Give a try

Code:
for value in 'a b c d e f'
  do
     echo $value
  done
  #6 (permalink)  
Old 07-04-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Code:
basic="a b c"
advance="d e f"

A="basic advance"

for g in $A
do
    eval echo \$$g
done
Closed Thread

Bookmarks

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 08:51 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