- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: UNIX arrays
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
тАО03-28-2005 06:22 AM
тАО03-28-2005 06:22 AM
UNIX arrays
I have written a script which has a line called "set -A array". When I execute it with
ksh <script name> it is executing fine. But the same when I tried without "ksh" it is giving an error called "Array parameter not set".
I have used "#!/usr/bin/ksh -eu" in the first line of the script but still it gives the error.
Can anyone please help.
Thanks,
Pat
- Tags:
- ARRAY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2005 06:46 AM
тАО03-28-2005 06:46 AM
Re: UNIX arrays
#!/usr/bin/ksh
or
#!/usr/bin/ksh -e
I'm not sure without testing how the -u set effects this, but its worth a try:
-u Treat unset parameters as an error when substituting.
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2005 06:56 AM
тАО03-28-2005 06:56 AM
Re: UNIX arrays
IE:
> which ksh
should be /usr/bin/ksh.
You could also run the script with -x to see what it is doing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2005 07:26 AM
тАО03-28-2005 07:26 AM
Re: UNIX arrays
I don't get the error when I remove the option 'u' from #!/usr/bin/ksh -e.
Can you please let me know why this happens.
Thanks,
Pat
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-28-2005 03:30 PM
тАО03-28-2005 03:30 PM
Re: UNIX arrays
#!/usr/bin/ksh
set -A array
echo ${array[0]}
then you will indeed get an error that element 0 is not set. Since array has not been assigned anything, set -u treats this as an error (a very good idea by the way) and stops the script. Now if the exact error message is: Array parameter not set" than you probably misspelled the array's name. NOTE: "Array" is not the same as "array". The following will run very differently if you type set -u before running it, and then type set +u and run it again:
#!/usr/bin/ksh
set -A array
echo $array
echo ${array[1]}
echo $Array
All 3 echo lines have arrors: the first is trying to echo an undefined array, the second is trying to show an undefined element (none have been defined) and the last line is a spelling error. So the -u option is flagging your script with an error message. If you leave set -u out of your script. your login shell probably has set +u in force so undefined variable are treated as null values, which is never a good idea. Always code set -u at the beginning of your scripts:
#!/usr/bin/ksh
set -u
set -A array
echo $array
echo ${array[1]}
echo $Array
Bill Hassell, sysadmin