- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Changing IFS within a shell script
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
тАО11-19-2003 07:40 PM - last edited on тАО10-21-2012 10:01 PM by Maiko-I
тАО11-19-2003 07:40 PM - last edited on тАО10-21-2012 10:01 PM by Maiko-I
Hi !
I need to access different column data files within the same shell script, but they use different field separators so that before doing
while read A B C
do
...
done < file.dat
I need to setup IFS to ";" for instance.
Once done that I would like to reset IFS to the original value (tabs, spaces) but doing
IFS="", or IFS=" " doesn't work like at the beginning.
How can I do that ?
At the beginning running
echo $IFS"+"
gives me back
$+
so that I thought the default value was "", but it's not that easy ... sigh.
Thanks in advance !
Cheers,
Mike
P.S. This thread has been moved from HP-UX > General to HP-UX > languages - HP Forums moderator
Solved! Go to Solution.
- Tags:
- IFS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-19-2003 07:59 PM
тАО11-19-2003 07:59 PM
Solutionhave you tried the simple approach; save the original value at the very beginning of your script:
SAVE_IFS="$IFS"
and then restore the value later...
IFS="$SAVE_IFS"
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-19-2003 07:59 PM
тАО11-19-2003 07:59 PM
Re: Changing IFS within a shell script
at the beginning of the script
SAVE_IFS=$IFS
...
work as needed
...
at the end of the script.
IFS=${SAVE_IFS}
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-19-2003 08:04 PM
тАО11-19-2003 08:04 PM
Re: Changing IFS within a shell script
echo "A${IFS}B"
A
B
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-19-2003 08:05 PM
тАО11-19-2003 08:05 PM
Re: Changing IFS within a shell script
Simply great, thanks to both, well earned !
Cheers,
Mike
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-21-2003 06:01 AM
тАО11-21-2003 06:01 AM
Re: Changing IFS within a shell script
(
IFS="${IFS}|"
while read A B C
do
.
.
.
done
)
The parenthesis set-up a sub-environment. You can even cd(1) within the parenthesis and outside them go back to where you were w/o having to record where you came from.
Enjoy,
-dlt-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-21-2003 06:09 AM
тАО11-21-2003 06:09 AM
Re: Changing IFS within a shell script
I implemented the backup and restore approach, but definitely this looks very elegant.
I'm still wondering if there's any chance to reset the value of IFS, without the need of restoring it through an external var.├Г┬╣
I odumped the value and it really looks a NULL, but it is not...
Again, thanks !
Mi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-21-2003 06:37 AM
тАО11-21-2003 06:37 AM
Re: Changing IFS within a shell script
thats just, what Davids approach does.
() creates a subenvironment, which ceases to exist after ), so you can do to IFS all you want and no need to restore it.
right Dave?
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-21-2003 06:44 AM
тАО11-21-2003 06:44 AM
Re: Changing IFS within a shell script
IFS=" \t\n"
do an print $IFS | vis -n to see the characters
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-27-2006 05:21 AM
тАО01-27-2006 05:21 AM
Re: Changing IFS within a shell script
Thanks to all those who helped me in this