- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- sh-posix script reading an array from a file with ...
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
тАО05-04-2005 08:14 PM
тАО05-04-2005 08:14 PM
Presently, I have code that looks like this:
GRAPH7[0]="CPU Summary"
GRAPH7[1]="Individual CPUs"
GRAPH7[2]="Disk Space"
Instead I want to read this array from a text file, so it can be maintained without editing the script. The text file looks like this:
CPU Summary
Individual CPUs
Disk Space
If I try this:
set -A GRAPH7 $( <7_day_graphs.ini )
I get each word assigned to a variable, instead of each line.
If I try this:
set -A GRAPH7 "$( <7_day_graphs.ini )"
I get only one variable in my array, with all the lines in it.
I can't figure out how to read one line at a time since each line contains spaces.
Any ideas?
Solved! Go to Solution.
- Tags:
- command substitution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-04-2005 10:04 PM
тАО05-04-2005 10:04 PM
Re: sh-posix script reading an array from a file with spaces in each element.
COUNT=0
while read line
do
GRAPH7[$COUNT]="$line"
((COUNT=$COUNT + 1))
done < 7_day_graphs.ini
Hope this helps,
-denver
- Tags:
- read
- while loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-04-2005 10:31 PM
тАО05-04-2005 10:31 PM
Re: sh-posix script reading an array from a file with spaces in each element.
while read line; do
operation $line
done < filename
If you want to assign into variable then,
index=0
read -r line; do
set GRAPH[$index]=$line
let index=index+1
done <
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-05-2005 01:31 AM
- Tags:
- IFS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-05-2005 12:19 PM
тАО05-05-2005 12:19 PM
Re: sh-posix script reading an array from a file with spaces in each element.
Thanks for the ideas!