- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- for loop 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
тАО04-07-2011 06:22 AM
тАО04-07-2011 06:22 AM
I have 3 values, each comprising 3 elements.
On the command line:
for i in '1 2 3' '4 5 6' '7 8 9' etc works
but in a script all hell breaks loose.
can anyone assist pls ?
I would like to run this within a script but Ive tried "'1 2 3' '4 5 6' '7 8 9' " and ''1 2 3' '4 5 6' '7 8 9' ' ...and both dont work.
Thks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-07-2011 06:25 AM
тАО04-07-2011 06:25 AM
Re: for loop question
elements="'123' '456' '789'"
and then do
for i in $elements ....
this is the bit that goes wrong.
Id like to setup a var in case I have a huge number of elements - thks and sorry for the confusion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-07-2011 06:49 AM
тАО04-07-2011 06:49 AM
Re: for loop question
> but in a script all hell breaks loose.
That's a useless description. Show us the script (or better an example case with code) and describe what you want to do and what does happen.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-07-2011 08:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-07-2011 11:02 AM
тАО04-07-2011 11:02 AM
Re: for loop question
You could create an array if there aren't more than 1023 elements:
set -A elements '123' '456' '789'
>for i in $elements ....
Replace by:
for i in "${elements[@]}"; do
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-07-2011 04:45 PM
тАО04-07-2011 04:45 PM
Re: for loop question
> this is the bit that goes wrong.
Have you considered the possible advantages
of explaining what you're actually doing, and
what actually goes wrong when you do it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-07-2011 07:22 PM
тАО04-07-2011 07:22 PM
Re: for loop question
Ok so "all hell breaks loose" was at tabd melodramatic. The new chastized me now says:
My previous efforts hitherto produced an array of results ranging from $i being equal to each entry in the group of elements or $i being equal to the entire string. These observations were when I assigned the groups to an array, albeit , incorrectly.
I see from the above how to correctly assign grouped elements to a variable to be used in the for loop.
Thks for all your comments and help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-07-2011 07:23 PM
тАО04-07-2011 07:23 PM