- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- output of a variable
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
тАО06-05-2008 04:20 AM
тАО06-05-2008 04:20 AM
I am having difficutly reading a variable in a while / for loop. I'm not sure whether it's because I have forgot or something else:
COLORS=#CC9999 #9999FF #FFCC88 #FF99FF #FFFF66 #FF9933 #CC9966 #990099"
for data in `echo $COLORS`^Jdo^Jecho $COLORS^Jdone
#CC9999 #9999FF #FFCC88 #FF99FF #FFFF66 #FF9933 #CC9966 #990099
#CC9999 #9999FF #FFCC88 #FF99FF #FFFF66 #FF9933 #CC9966 #990099
#CC9999 #9999FF #FFCC88 #FF99FF #FFFF66 #FF9933 #CC9966 #990099
#CC9999 #9999FF #FFCC88 #FF99FF #FFFF66 #FF9933 #CC9966 #990099
#CC9999 #9999FF #FFCC88 #FF99FF #FFFF66 #FF9933 #CC9966 #990099
#CC9999 #9999FF #FFCC88 #FF99FF #FFFF66 #FF9933 #CC9966 #990099
#CC9999 #9999FF #FFCC88 #FF99FF #FFFF66 #FF9933 #CC9966 #990099
#CC9999 #9999FF #FFCC88 #FF99FF #FFFF66 #FF9933 #CC9966 #990099
I dont want this - I want each $VAR to be printed on a seperate line.
Am i being dumb?
thanks
Chris.
Solved! Go to Solution.
- Tags:
- for loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2008 04:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2008 04:26 AM
тАО06-05-2008 04:26 AM
Re: output of a variable
COLORS="#CC9999 #9999FF #FFCC88 #FF99FF #FFFF66 #FF9933 #CC9966 #990099"
for VAR in ${COLORS}
do
echo ${VAR}
done
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2008 04:38 AM
тАО06-05-2008 04:38 AM
Re: output of a variable
Thats how I feel - a dumb question which I should have seen but thanks guys I think I will go home for the day!!
Chris.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-05-2008 04:50 AM
тАО06-05-2008 04:50 AM
Re: output of a variable
Before you go home, please consider what you are going to do with the individual words once you have them.
I find that all too often folks then fo into awk or perl or further process.
In that case, use such tool to do both the splitting and the next processing step(s).
For sake of completeness here are two frames:
awk:
# echo $COLORS | awk '{while (i
Perl:
# $ echo $COLORS | perl -lne 'print foreach (split)'
# $ export COLORS
$ perl -le 'foreach (split /\s+/, $ENV{COLORS}) { print }'
# echo $COLORS | perl -pe '$_ = join "\n",split'
adding that last newline....
echo $COLORS | perl -pe '$_ = (join "\n",split) . "\n"'
hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-06-2008 01:35 AM
тАО06-06-2008 01:35 AM