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
Need Help with awk and arrays fusionX Shell Programming and Scripting 7 02-11-2008 06:41 PM
awk arrays imonthejazz Shell Programming and Scripting 1 09-21-2007 09:29 AM
arrays in awk??? craigsky Shell Programming and Scripting 3 08-27-2007 09:13 PM
ksh script - arrays sidamin810 Shell Programming and Scripting 13 07-18-2005 03:07 AM
Two or more arrays in Awk nitin UNIX for Advanced & Expert Users 1 12-10-2001 09:37 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-24-2005
whited05 whited05 is offline
Registered User
  
 

Join Date: Jun 2005
Posts: 9
Unhappy KSH and arrays

hello all,

I browsed the forum (briefly) and I am having issues with a script I writing. I need to check a directory and see if there are files there, if so process all of them. The issues I am having is that when I create the array of files names using set -A filenames "$(ls -1 $OES_DATA_IN_DIR)"
when I try to iterate through this using a for loop or a while loop I keep getting all entries. Here are the test scripts. I have 2 files in the $OES_DATA_IN_DIR directory.

#! /usr/bin/ksh
Filename=OFFER_INVENTORY_*.dat
if [ -f $OES_DATA_IN_DIR/$Filename ]
then
set -A filenames "$(ls -1 $OES_DATA_IN_DIR)"
typeset fname
typeset -R10 del
typeset -L6 delDate
let count=0
while (( $count < ${#filenames[*]} )); do
fname="${filenames[count]}"
export fname
del=$fname
delDate=$del
echo $fname
echo $del
echo $delDate
let count="count + 1"
done
fi


Here is the output
oeosdev@grampian$ ksh array.sh
OFFER_INVENTORY_200506.dat OFFER_INVENTORY_200507.dat
200507.dat
200507
oeosdev@grampian$

Now for a for loop
#! /usr/bin/ksh
Filename=OFFER_INVENTORY_*.dat
if [ -f $OES_DATA_IN_DIR/$Filename ]
then
typeset fname
typeset -R10 del
typeset -L6 delDate
let count=0
for filenames in "$(ls -1 $OES_DATA_IN_DIR)"; do
fname="${filenames[count]}"
export fname
del=$fname
delDate=$del
echo $fname
echo $del
echo $delDate
done
fi
Here is the oputput.

oeosdev@grampian$ ksh array2.sh
OFFER_INVENTORY_200506.dat OFFER_INVENTORY_200507.dat
200507.dat
200507


What I need the oputput to be is
OFFER_INVENTORY_200506.dat
200506.dat
200507
OFFER_INVENTORY_200507.dat
200507.dat
200507
  #2 (permalink)  
Old 06-24-2005
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
Try changing
"$(ls -1 $OES_DATA_IN_DIR)"
to just
$(ls -1 $OES_DATA_IN_DIR)
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 06:56 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