- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: for loop question and change of IFS
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
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
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
08-17-2011 02:52 AM
08-17-2011 02:52 AM
hello,
i am wondering , why a for-loop doesn't work
i store hostname's in variable and then i use "for"
COPY_HOSTS="host1 host2"
for copy_host in ${COPY_HOSTS}
do
echo "copy_host: ${copy_host}"
done
###########################
output ( ok )
copy_host: host1
copy_host: host2
but then i am wondering, when this statement doesn't work in a big shell script and produces following output:
copy_host: host1 host2
then i try to fix it and found statements above like " while IFS=':' ".
this has a impact for a "for loop" in this case ?
so i save before the "for loop" the IFS
SAVE_FS="${IFS}"
IFS=" "
right ?
after "for loop"
IFS="${SAVE_FS}"
regards
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2011 03:56 AM
08-17-2011 03:56 AM
Re: for loop question and change of IFS
>found statements above like " while IFS=':' ". This has a impact for a "for loop" in this case?
Right. If IFS isn't set to split up the variable COPY_HOSTS, there is only one string there.
>so I save before the "for loop": SAVE_FS="${IFS}"
>IFS=" "
>after "for loop": IFS="${SAVE_FS}"
Yes. Or set it to the default, " \t\n", where \t is really a tab and \n is really ctrl-V ctrl-J.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2011 05:34 AM
08-17-2011 05:34 AM
SolutionHI:
In my opinion, the safest way to change the shell's IFS is to save the old value and restore that after your operations are complete:
OLDIFS=${IFS} ... IFS=${OLDIFS}
If you try to set to the IFS to whitespace (a blank, a tab, and/or a newline) and ever use 'expand' to change your script's tab to strings of blanks you will be unpleasantly surprised.
Regards!
...JRF...