- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: shell 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
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
тАО04-10-2003 04:08 AM
тАО04-10-2003 04:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-10-2003 04:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-10-2003 04:18 AM
тАО04-10-2003 04:18 AM
Re: shell script
e.g. in korn/posix
i[0]="foo"
i[1]="bar"
i[2]="baz"
for x in 0 1 2
do
echo ${i[${x}]}
done
HTH
Duncan
I am an HPE Employee
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-11-2003 01:24 AM
тАО04-11-2003 01:24 AM
Re: shell script
Yes you can...
Like in any other programming languages Arrays in Korn SHELL are variables that contain more than one value.
example...
integer my_array
my_array[0]=5
my_array[1]=16
The first element of an array is indexed by 0, the second element is 1, and so on. The largest index value that is valid for array is 1023.
You must enclose an array reference in braces for the korn shell to recognize it as such.
For example...
${my_array[1]}
Instead of...
$my_array[1]
The syntax for accessing the value of the nth array element is, where n is an integer... {my_array[n]}
To print the values of all array elements, use the syntax: {my_array[*]}
To print the actual number of elements (assigned values) in the array use the syntax: {#array_name[*]}
Array elements do not have to be assigned in order. Moreover, you can skip the assignment of values to any elements you want. For instance....
my_array[2]=2
my_array[5]=3
my_array[1023]=1
Array elements that are skipped over are not assigned a value and, effectively, are treated as though they do not exist.
Hope this helps...
best regards...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-11-2003 01:48 AM
тАО04-11-2003 01:48 AM
Re: shell script
In k-shell use set with -A option to declare an array and read output of a command into the array in one step.
$ set -A users `awk -F: '{print $1}' /etc/passwd`
$ echo ${users[0]}
root
hope this helps.
- ramd.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-11-2003 01:27 PM
тАО04-11-2003 01:27 PM
Re: shell script
Use this URL documentation for compelete reference also:
http://docs.hp.com/hpux/pdf/B2355-90046.pdf
Thanks
Zafar