- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Korn shell question
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
Discussions
Discussions
Forums
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
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
тАО02-05-2008 05:13 AM
тАО02-05-2008 05:13 AM
I wanted to write a ksh script that uses arrays.
Since I was not familiar with the syntax, I looked up some code on the net.
This is what I found:
"
typeset -A wavelength
wavelength["red"]=650
wavelength["orange"]=590
wavelength["green"]=510
wavelength["blue"]=475
wavelength["indigo"]=445
wavelength["violet"]=400
"
This is what I want to do but when test this code then 'typeset -A' is not recognised.
If replace 'typeset -A' by 'set -A' then I get 'red: bad number'
It seems that version of Korn shell on my system is to old (not Korn 93). I am running 11.11.
Is this correct or is the syntax just wrong?
Any help much appreciated.
KRis
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2008 05:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2008 05:25 AM
тАО02-05-2008 05:25 AM
Re: Korn shell question
It may well be that an Ksh script with arrays is the optimal (learning, processing, price, security, tools) way to solve the challenge on hand.
However, in my experience most such task are better done in AWK or PERL.
What problem are you really trying to solve?
Outline it here (with concrete input and output) and we may be able to help you better.
Regards,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2008 05:27 AM
тАО02-05-2008 05:27 AM
Re: Korn shell question
with set -A you can only use integer as index of the array. check man ksh
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2008 07:20 AM
тАО02-05-2008 07:20 AM
Re: Korn shell question
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2008 07:26 AM
тАО02-05-2008 07:26 AM
Re: Korn shell question
what you want is a hash
(or a so called associative array).
I am not into Korn shell in particular
because I never require it.
As for most array capable shells,
they expect indeces to be unsigned integers
(often only ranging from 0-1023).
But you can script in awk, Perl, Python or Ruby for key value paired lists.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2008 07:59 AM
тАО02-05-2008 07:59 AM
Re: Korn shell question
Moreover,I'm convinced that ksh array is a standard 1-level array with index. I.e you should use : wavelength[1]="red",[2]="orange" and so on. What you may need here is a named reference. It is nicely implemented with perl's hashes. ksh93 gives associative arrays,as well,there you can use strings as an index.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-05-2008 08:16 AM
тАО02-05-2008 08:16 AM
Re: Korn shell question
While I agree that associative arrays are better handled in 'awk' or Perl (where they are called "hashes"), you _CAN_ do this with the Korn93 shell _ON_ HP-UX with as I noted above. You must use :
/usr/bin/dt/dtksh
Regards!
...JRF...