- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Do arrays work in the posix shell?
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
тАО11-19-2006 08:18 AM
тАО11-19-2006 08:18 AM
Tell me I'm dumb! :-)
Could someone provide a working example of how to assign three values to one array variable and then reference them?
Solved! Go to Solution.
- Tags:
- ARRAY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-19-2006 08:55 AM
- Tags:
- set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-19-2006 09:10 AM
тАО11-19-2006 09:10 AM
Re: Do arrays work in the posix shell?
You definitely did exactly what I asked, and now having seen that I realize I was very close in my own attempts, but I had forgotten the numbering started at 0, so when I was assigning using "set" and then referencing ${a[1]}, the shell was telling the truth when it claimed the variable wasn't set. D'OH! :-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-19-2006 11:34 AM
тАО11-19-2006 11:34 AM
Re: Do arrays work in the posix shell?
set -A REASON \
"exceeded password lifetime" \
"exceeded last login time" \
"exceeded absolute account lifetime" \
"exceeded unsuccessful login attempts" \
"password required and a null password" \
"administrator lock" \
"password is a * (asterisk)"
You can display all the defined elements with @ like this:
echo "${REASON[@]}"
or show the elements by number:
for N in 0 1 2 3 4 5 6
do
echo "$N = \"${REASON[$N]}\""
done
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-19-2006 09:04 PM
тАО11-19-2006 09:04 PM
Re: Do arrays work in the posix shell?
to make Bill's solution a little more general, you can loop through an array without explicitly naming the indices:
Change
>>
for N in 0 1 2 3 4 5 6
do
echo "$N = \"${REASON[$N]}\""
done
<<
To
typeset -i N=-1
while [ N+=1 -lt ${#REASON[*]} ]
do print $N = \"${REASON[N]\"
done
mfG Peter
- Tags:
- typeset
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-20-2006 12:17 AM
тАО11-20-2006 12:17 AM