- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- juggling with variables and arrays under the POSIX...
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
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
тАО05-08-2007 04:10 AM
тАО05-08-2007 04:10 AM
I am having trouble concatenating variables into a useful command. I'm working with (pseudo?)arrays under /sbin/sh.
Behold !
lhpdev0(/)# echo $SHELL
/sbin/sh
lhpdev0(/)# echo $i
35
lhpdev0(/)# echo $bd35
lhpdev0.avdl.com
$i is an iteration counter
$bd35 is the first index of an array
I get stuck trying to get a value out of bd$i.
I have tried fooling around whith braces, that didnt help.
lhpdev0(/)# echo $bd$i
sh: bd: Parameter not set.
lhpdev0(/)# echo $bd${i}
sh: bd: Parameter not set.
lhpdev0(/)# echo ${bd${i}}
sh: ${bd${i}}: The specified substitution is not valid for this command.
So how would I work the shell's magic to obtain say the first index of $bd[0-35], using the iteration counter $i ?
TIA !
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 04:31 AM
тАО05-08-2007 04:31 AM
Re: juggling with variables and arrays under the POSIX shell
Here is some more background.
I have a number of arrays ( bd0 through bd?? ) and at some point in my script I will need to get the value of an index for each of them.
I planned on doing a while loop, using good o'l i as the iteration counter, and getting the index I need for each array up to ?? with something like this :
Note "bds" is an array containing the list of bd arrays :)
i=0
while [ $i -lt ${#bds[*]} ]
do
echo ${bd${i}[0]} <---Need help here!
((i=i+1))
done
Hope this helps you guys understand what my goal is.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 04:44 AM
тАО05-08-2007 04:44 AM
Re: juggling with variables and arrays under the POSIX shell
set -A bd red green blue purple
i=0
while [ $i -lt ${#bd[*]} ]
do
echo ${bd[$i]}
i=$(($i +1))
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 04:54 AM
тАО05-08-2007 04:54 AM
Re: juggling with variables and arrays under the POSIX shell
I am using $i to cycle through a list of arrays, retrieving a fixed index.
Keep 'em coming :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 05:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 05:03 AM
тАО05-08-2007 05:03 AM
Re: juggling with variables and arrays under the POSIX shell
eval does the trick
Thanks guys !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-08-2007 05:17 AM
тАО05-08-2007 05:17 AM
Re: juggling with variables and arrays under the POSIX shell
You aren't using arrays. As you already stated
>with (pseudo?)arrays
My point was to use actual arrays (not directly implied).