Array in Ksh Shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Array in Ksh Shell script
# 1  
Old 05-09-2011
Array in Ksh Shell script

hi team,
i have a file, which contains only variable and its value
Code:
 
param.ksh
---------
export A=123
export B=345
export C=567
export D=OPLI
export E=OL89PO

From shell script, i am invoking this file and use the value of this variable. Now there are 5 variable in above file. Before i start using these variables, i want to check if all 5 variables are available in param file and if yes, all variables have values assigned. If any of the variable is missing or value is not assigned to it, it will exit the process.
I have tried using aray, but it is not working properly.
Code:
 
set -A ARRAY "A" "B" "C" "D" "E"
for i in "${ARC_ARRAY[@]}"
do
 echo ${i}
 if [ -z ${i} ]
 then
  echo "Parameter ${i} does not defined in param.ksh file"
 fi
done

# 2  
Old 05-09-2011
For one thing you define ARRAY then use ARC_ARRAY. I think you're looking for something like this...

Code:
$
$ cat array
#! /bin/ksh

export A=123
export B=345
export C=567
export D=OPLI
export E=OL89PO

set -A ARRAY "A" "B" "C" "D" "E"
for i in "${ARRAY[@]}"
do
 eval value=\$$i
 echo ${i} = $value
 if [ -z ${value} ]
 then
  echo "Parameter ${i} does not defined in param.ksh file"
 fi
done
$
$
$ ./array
A = 123
B = 345
C = 567
D = OPLI
E = OL89PO
$

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass and read an array in ksh shell script function.?

I'm able to read & print an array in varaible called "filelist" I need to pass this array variable to a function called verify() and then read and loop through the passed array inside the function. Unfortunately it does not print the entire array from inside the funstion's loop. #/bin/ksh... (5 Replies)
Discussion started by: mohtashims
5 Replies

2. Shell Programming and Scripting

Pass C shell array to another C shell script(csh) and shell(sh)

Dear Friends, Please help me on this my script name is send.csh In this i have written the statement like this set args = ( city state country price ) I want to pass this array to another c shell called receiver.csh. and i want to use it in this c shell or how to pass to... (2 Replies)
Discussion started by: SA_Palani
2 Replies

3. Shell Programming and Scripting

Need Shell Script for Array

Hi all, I have an input file like below (a comma seperated file) 345,12,10 400,11,8 328,1,3 I need to get the output as below ... record 345 sum is 12 record 400 sum is 10 record 328 sum is 1 record 345 count is 10 record 400 count is 8 record 328 count... (15 Replies)
Discussion started by: hemanthsaikumar
15 Replies

4. Shell Programming and Scripting

Array in shell script

Hi, check=("/usr/local/bin/chk_nag | awk -F":" '{print $1}'" "/usr/local/bin/chk_kas | awk -F":" '{print $1}'" "/usr/local/bin/chk_was | awk -F":" '{print $1}'" ) for i in "${check}"; do echo $i; done when I run this. It says Syntax error: "(" unexpected Please advise. (5 Replies)
Discussion started by: ashokvpp
5 Replies

5. Shell Programming and Scripting

How to append to array within conditional block in ksh/korn shell?

Hi, I have one array created and some values are there in ksh. I want to append some other values to it based on some condition in if statement. #!/bin/ksh echo "---------------------------------------------------" set -A ipaddr_arr $(egrep -v '^#|^::|^$' /etc/hosts |awk '{print $1}'... (2 Replies)
Discussion started by: sanzee007
2 Replies

6. Shell Programming and Scripting

Help with ksh shell script

Anyone know how to check a filename that contains a date and compare whiich file is older using a ksh shell script? The filename looks like aaaaa_20110615 (1 Reply)
Discussion started by: Bperl1967
1 Replies

7. Shell Programming and Scripting

Passing array to functions in ksh script

Let me know if there is a way to pass array to a funtion in ksh script. function isPresent { typeset member member=$1 dbList=$2 echo '$1:' $1 echo '$2' $dbList The array will be at the second position....something like this isPresent 12 <array> if then echo... (3 Replies)
Discussion started by: prasperl
3 Replies

8. Shell Programming and Scripting

Help with ksh shell script

I am using /usr/bin/ksh in AIX I am reading the values of $dbname, $dbatmpdir/dbdir.$$, and $scope from a different file All I have to do is check if $dbname exists in file $dbatmpdir/dbdir.$$ and $scope should have a value either 'TABLE' or 'SCHEMA'. When I execute the following code. I am... (3 Replies)
Discussion started by: tenderfoot
3 Replies

9. Shell Programming and Scripting

How to define array in Bourne shell , csh & ksh

Dear friends... Kindly if any one can help me to know the differences in definning & retreiving data from arrays in the sh,csh & ksh. I always facing problems in this issue. thanks...:) BR (3 Replies)
Discussion started by: ahmad.diab
3 Replies

10. Shell Programming and Scripting

KSH script not looping through array

Hi All, I'm trying to get a script to loop through an array. The array is basically a list of .zip files. I'd like the script to loop through and unzip the zip files contained in the zip file list. When I run the script, it unzip the first zip file correctly, and then stops Any thoughts? Here's... (2 Replies)
Discussion started by: kelldan
2 Replies
Login or Register to Ask a Question