Setting values in an array? Easy one


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Setting values in an array? Easy one
# 1  
Old 11-29-2005
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!
# 2  
Old 11-29-2005
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

# 3  
Old 11-29-2005
also:

for i in `echo key1 key2 key3 ...`
do
echo $i
done
# 4  
Old 11-29-2005
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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Reading properties from file and setting variable values

I want to read properties from a file and print evaluated values of each key. I am using AIX6.1. myfile.props protocol=http siteA.host=siteAhostname pageA=pageNameA siteAURL1=${protocol}:/${siteA.host}/pagea/blabla?v1=32 siteAURL2=${protocol}:/${siteA.host}/${pageA}/blabla?v1=32... (5 Replies)
Discussion started by: kchinnam
5 Replies

2. Shell Programming and Scripting

Bash: Setting default values for variables

I have a variable I want to use in bash script. The user will pass an argument to the script and I will store it in `arg_fql`. If the user does not pass the variable, I still never set arg_fql, but I set another variable to a default. However, if the user passes a value, `arg_fql` will be set to... (2 Replies)
Discussion started by: kristinu
2 Replies

3. Red Hat

Values in array are not able to be used one by one

hey,i stored the value of an sql query in an array and then tried to use that value in while loop. actually my array will have two or more values, then according to the values i have to display result. #!/bin/bash -xv val_1=$( sqlplus -s rte/rted1@rel75d1 << EOF set heading off select... (1 Reply)
Discussion started by: ramsavi
1 Replies

4. Shell Programming and Scripting

help in setting up values

I have server, i want to tune some storage below are my issues. 1. There is a directory /sys/block/ There are directories starting with name emcpow* under that there is a directory queue, inside that there is file nr_requests This is complete path ... (3 Replies)
Discussion started by: learnbash
3 Replies

5. HP-UX

max limit in in setting array

hi, iam getting error when i assign a variable to an array of more that 315 character in length set -A array <variable> <variable> value is 000001 000002 and up to 000045 it is giving error as "The specified subscript cannot be greater than 1024." can any one help me to solve this (2 Replies)
Discussion started by: gomathi
2 Replies

6. Shell Programming and Scripting

PHP: Search Multi-Dimensional(nested) array and export values of currenly worked on array.

Hi All, I'm writing a nagios check that will see if our ldap servers are in sync... I got the status data into a nested array, I would like to search key of each array and if "OK" is NOT present, echo other key=>values in the current array to a variable so...eg...let take the single array... (1 Reply)
Discussion started by: zeekblack
1 Replies

7. Shell Programming and Scripting

Setting array equal to command response

normally when i type: condor_q | tail -1 command line returns: 0 jobs; 0 idle, 0 running, 0 held I want use the number in front of 'running' in a series of equality tests to submit more jobs when my queue gets low. Someone showed me how to do it a few days ago by setting an array equal to... (4 Replies)
Discussion started by: pattywac
4 Replies

8. Shell Programming and Scripting

KSH Setting multiples variables with an array

ih all, info=$(get_Info $daemon) # $info give : # "ev20 8800 TTIOGC 12345 astos EDITEUR 0 0 . ." server=$(echo $info | cut -d" " -f1) port=$(echo $info | cut -d" " -f2) dname=$(echo $info | cut -d" " -f3) dport=$(echo... (1 Reply)
Discussion started by: wolfhurt
1 Replies

9. Shell Programming and Scripting

dynamically setting an array

Hi Gurus, How do I dynamically set up an array. Below is my code if ] then set ecomm_task_limit = '${ecomm_srvr}' fi Here, I want to set values in the array "${ecomm_srvr}" into ecomm_task_limit upon each iteration. Finally I want to display all the values in the new array... (4 Replies)
Discussion started by: ragha81
4 Replies

10. UNIX for Dummies Questions & Answers

Need help on installing an EASY to use and easy to install command line text editor

Hi again. Sorry if it seems like I'm spamming the boards a bit, but I figured I might as well ask all the questions I need answers to at once, and hopefully at least get some. I have installed Solaris 10 on a server. The default text editors are there (vi, ex, ed, maybe others, I know emacs is... (4 Replies)
Discussion started by: EugeneG
4 Replies
Login or Register to Ask a Question