- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: IFS Internal Field Separator
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
Forums
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
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
тАО02-09-2006 02:12 PM
тАО02-09-2006 02:12 PM
$#newline inside a script (to preserve tabs,
$#leading spaces, whatever). Interactively,
$IFS=" #<---- nothing invisible except CR
>" #<---- ditto.
$#this works ok, too, and
$echo $IFS | od -b
0000000 012
0000001
$#LOOKS almost as I'd expect, though I'm told $#that echo added the 012 (LF) I don't $#believe it - there'd be one on the next $#line too, right? Anyway, I'd like to do $#this in a script, where you can't see $#what's typed and probably can't remember $#either, so it would be really nice to be
$#visibly specify exactly what I want, such
$#as
$IFS=%012 #or better imho...
$IFS=$0A
$#I tried
$IFS=\n
$#and very curiously get the same result from $echo IFS | od -b
$# but it sure doesn't work!
TIA
Solved! Go to Solution.
- Tags:
- IFS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-10-2006 03:22 AM
тАО02-10-2006 03:22 AM
Re: IFS Internal Field Separator
You did not get any suggestion so far, perhaps because forum performance has been spotty (being nice here :-), or perhaps because your topic looks a little confusing (beging nice here :-).
Anyway...
For a simple discussion on IFS try: Google +shell +ifs [I'm feeling lucky]
But you seem to know that already.
What problem are you really trying to solve?
As much as I like reduced, simplyfied examples you may have oversimplyfied and lost the point in your description.
There may be better tools (awk, perl,...) that avoid the word breaks.
Maybe, just mabye, your problem is solved by just assigning IFS to nothing?
Example (similar to that liverfile example):
# line="learn unix at livefire labs"
# for i in $line
> do
> echo $i
> done
learn
unix
at
livefire
labs
# IFS=
# for i in $line
> do
> echo $i
> done
learn unix at livefire labs
#
KISS!
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-10-2006 03:34 AM
тАО02-10-2006 03:34 AM
Re: IFS Internal Field Separator
Is there an unambiguous way to express control characters to the Posix shell?
I'd like something like
IFS=%012 # Octal 012, a LineFeed char.
IFS=$0A # Hex 0A, same character.
IFS=ascii(10) #again same character.
which would be handy not only for clearly setting IFS but also for clearly restoring it!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-10-2006 03:42 AM
тАО02-10-2006 03:42 AM
Solutionbs=`echo "\010"`
However, since linefeed is a special character used for record seperation within text files, I don't think it's going to work.
If you set IFS to null, then I think you will get the results you are looking for.
perl or awk might be better tools for string processing of a file.
HTH
-- Rod Hills
- Tags:
- echo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-10-2006 06:31 AM
тАО02-10-2006 06:31 AM
Re: IFS Internal Field Separator
$IFS="\012"
should work to set IFS = linefeed aka newline, but no...
$ IX="
> "
$ echo $IX | od -b
0000000 012 012
0000002
$ IX="\012"
$ echo $IX | od -b
0000000 134 040 040 012
0000004
but
$ IX="\001\002\003\004\005\006\007\010\012\013\014\015\020"
$ echo $IX | od -b
0000000 001 002 003 004 005 006 007 010 012 013 014 015 020 012
0000016
$# what's happening here?
$# and shouldn't IFS typically be \040\011\012 (space,tab,linefeed)? mine seems to default to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-10-2006 06:53 AM
тАО02-10-2006 06:53 AM
Re: IFS Internal Field Separator
If you simply unset IFS you will preserve leading spaces and tabs upon reading. No word splitting is done:
#!/usr/bin/sh
OLDIFS=${IFS}
IFS=
while read LINE
do
echo ${LINE}
done
IFS=${OLDIFS}
Does this help?
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-10-2006 10:18 AM
тАО02-10-2006 10:18 AM
Re: IFS Internal Field Separator
$oldIFS=$IFS #good idea
$# and
$IFS=
$# are good; using that IFS setting works. so my questions become entirely academic, no quick answers:
1) in the HPUX shell user guide (posix section) the intro says IFS behavior is different from Bourne, "IFS variable is effective only for read, results of parameter expansions and command substitution; it is always initialized."
and later in a table "Shell parms" it says
"IFS:Internal Field Separators (usually space, tab, and new-line), which are used to separate command words during command or parameter substitution and when using the read command." OK, let's test that:
$sh
$echo $IFS | od -b
0000000 012
0000001
$# I see nothing here; does that mean od -b doesn't work?
$read line
3spacesthentabhere: thenspacehere: theend.
$echo $line
3spacesthentabhere: thenspacehere: theend.
$# so spaces and tabs are being removed, but why? I sure didn't see them in IFS.
$IFS=
$echo $IFS | od -b
0000000 012
0000001
$read line
3spacesthentabhere: thenspacehere: theend.
$echo $line
3spacesthentabhere: thenspacehere: theend.
$# it's working now. why?
$# also, what's happening here?:
$IFS=
$read line
tab3spacesthenthisthentab: thenthisthentab: theend.
$echo $line
tab3spacesthenthisthentab: thenthisthentab: theend.
$echo $IFS | od -b
0000000 012
0000001
$IFS="\011\012\040"
$echo $IFS | od -b
0000000 134 040 040 040 134 040 040 040 134 040 040 012
0000014
$#WTF?
$IFS="
> "
$echo $IFS | od -b
0000000 012
0000001
$IFS="\011\012"
$echo $IFS | od -b
0000000 134 040 040 040 134 040 040 012
0000010
$#I have examples of \011 really being loaded to IFS, but not always. any clues?
$#I'm about to start smoking again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-10-2006 10:44 AM
тАО02-10-2006 10:44 AM
Re: IFS Internal Field Separator
Try-
echo "$IFS" | od -b
to see the contents.
Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-10-2006 11:39 AM
тАО02-10-2006 11:39 AM
Re: IFS Internal Field Separator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-10-2006 11:43 AM
тАО02-10-2006 11:43 AM