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
incorrect array values jhillier UNIX for Dummies Questions & Answers 6 01-04-2008 01:44 AM
printing all array values using dbx 7.2.1 JamesGoh High Level Programming 1 12-18-2007 01:07 PM
to assign cut values to an array Syms UNIX for Dummies Questions & Answers 6 10-29-2007 03:42 AM
Assigning values to an array yongho UNIX for Dummies Questions & Answers 4 07-13-2005 05:49 PM
array values in a command eeisken Shell Programming and Scripting 3 06-22-2005 01:49 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-29-2005
Registered User
 

Join Date: Feb 2005
Posts: 30
Setting values in an array? Easy one

I need to do something like this:

Code:
KEYS=[key1,key2,key3,key4]

for key in $KEYS
do
echo $key
done
The KEYS are static values in my script, I'm just having trouble with setting them as separate values.

Thanks!
Reply With Quote
Forum Sponsor
  #2  
Old 11-29-2005
Registered User
 

Join Date: Jan 2005
Posts: 682
KSH examples:

as a list:

Code:
#! /usr/bin/ksh

typeset IFS=,
KEYS=key1,key2,key3,key4
for i in ${KEYS}
do
    echo $i
done
or as an array

Code:
#! /usr/bin/ksh

set -A KEYS key1 key2 key3 key4
for i in ${KEYS[@]}
do
    echo $i
done
Reply With Quote
  #3  
Old 11-29-2005
Registered User
 

Join Date: Nov 2005
Posts: 11
also:

for i in `echo key1 key2 key3 ...`
do
echo $i
done
Reply With Quote
  #4  
Old 11-29-2005
Registered User
 

Join Date: Oct 2002
Posts: 676
Quote:
Originally Posted by ppierald
also:

for i in `echo key1 key2 key3 ...`
do
echo $i
done

No need to echo:

Code:
for i in key1 key2 key3
do
echo $i
done
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:59 PM.


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

Content Relevant URLs by vBSEO 3.2.0