- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Using arrays in ksh script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2004 02:36 AM
01-29-2004 02:36 AM
I'm trying to use arrays in a ksh script.
I'm implementing an example found on the forum.
But it doesn't work and I can't see why !
the commands are :
DAYS[0]=Mon
DAYS[1]=Tue
DAYS[2]=Wed
print $DAYS
print $DAYS[0]
print $DAYS[1]
print $DAYS[2]
and the result is :
DAYS: not found
DAYS: not found
DAYS: not found
Where is the problem ? (Am I using a wrong ksh ?)
Thanks for your help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2004 02:40 AM
01-29-2004 02:40 AM
Solutioncolour[0]=red
colour[1]=blue
colour[2]=red
colour[3]=green
colour[4]=green
colour[5]=blue
colour[6]=yellow
colour[7]=cyan
colour[8]=red
colour[9]=blue
echo ${colour[2]}
That will output "red"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2004 02:44 AM
01-29-2004 02:44 AM
Re: Using arrays in ksh script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2004 02:47 AM
01-29-2004 02:47 AM
Re: Using arrays in ksh script
#!/usr/bin/ksh
DAYS[0]="Mon"
DAYS[1]="Tue"
DAYS[2]="Wed"
#Now try this:
print $DAYS[1]
print ${DAYS[1]}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2004 03:02 AM
01-29-2004 03:02 AM
Re: Using arrays in ksh script
colour[0]=red
colour[1]=blue
colour[2]=red
colour[3]=green
colour[4]=green
colour[5]=blue
colour[6]=yellow
colour[7]=cyan
colour[8]=red
colour[9]=blue
COUNTER=0
while test "$COUNTER" -lt "10"
do
echo $COUNTER ${colour[$COUNTER]}
(( COUNTER = "$COUNTER" + "1" ))
done
You can see the syntax of how the subscript works then.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2004 03:30 AM
01-29-2004 03:30 AM
Re: Using arrays in ksh script
It's MUCH EASIER this way !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2004 04:06 AM
01-29-2004 04:06 AM
Re: Using arrays in ksh script
It's easy to get confused with Arrays. Following script may give you little more information on ARRAYs.
set -A ARRAY
ARRAY[0]="elem 1 "
ARRAY[1]="elem 2"
ARRAY[2]="elem 3"
ARRAY[3]="elem 4"
ARRAY[4]="elem 5"
typeset -i num_elms=${#ARRAY[@]}
typeset -i count=0
while [ $count -lt num_elms ]
do
echo "ARRAY[$count] is ${ARRAY[$count]}"
(( count = $count + 1 ))
done
-Sri