set IFS to x00

set IFS to x00

Post by John Kell » Mon, 10 Oct 2005 08:52:41



Any way to set IFS to 0x00?  I can't seem to think of a way.
 
 
 

set IFS to x00

Post by Enrique Perez-Terro » Mon, 10 Oct 2005 09:14:31



> Any way to set IFS to 0x00?  I can't seem to think of a way.

   IFS=$'\0'

But I am not sure how well the shell handles binary zeros in strings.
I guess that depends on what shell.

-Enrique

 
 
 

set IFS to x00

Post by John Kell » Mon, 10 Oct 2005 09:45:19


On Sun, 09 Oct 2005 02:14:31 +0200, "Enrique Perez-Terron"



>> Any way to set IFS to 0x00?  I can't seem to think of a way.

>   IFS=$'\0'

Thanks, Enrique, I could not think of that $'string' syntax.

Quote:>But I am not sure how well the shell handles binary zeros in strings.

To bash,

IFS=$'\0'

looks the same as

IFS=

because they both report 0 length.  However,

IFS=$'\1'

does report a length of 1, and matches on a comparison test.

I'm going to try using IFS=$'\x1C' as a field separator when I pipe
some data from one while read loop into another.  I can insert the hex
value between fields with printf.

Thanks for getting me on the right track.

 
 
 

set IFS to x00

Post by Stephane CHAZELA » Mon, 10 Oct 2005 18:26:59


2005-10-09, 02:14(+02), Enrique Perez-Terron:

>> Any way to set IFS to 0x00?  I can't seem to think of a way.

>    IFS=$'\0'

> But I am not sure how well the shell handles binary zeros in strings.
> I guess that depends on what shell.

[...]

Only zsh can cope with $'\0'. And the NUL character is in IFS by
default in zsh (along with SPC, TAB and NL as in other shells).

Note however that, by the very nature of them *environment*
variables can't contain NUL characters.

--
Stphane

 
 
 

1. Question regarding IFS and set -- : Why does it take two iterations?

I am using IFS to parse out a line in sh (actually, bash under Linux).

I have something like:

        foo=`IFS=/;set -- /foo/bar/bletch/some/filename;echo $5`

However, it doesn't work.  After the first 'set', everything is in $1, not
in the other args (although it does convert the slashes into spaces).
To get what I really want, I have to do:

        foo=`IFS=/;set -- /foo/bar/bletch/some/filename;set -- $1;echo $5`

This correctly gets me 'some' (Note that $1 is null).

But why do I need the additional 'set' command?  Is this WAD (*) ?
It seems to me that the first form ought to work.

(*) Working as designed.

************************************************************************
Are you joking?  DOS applications in WinNT?  WinNT is just a toy
you install on your machine, to give more shine to OS/2's glory.
                - Mikael Wahlgren -


          hundreds, if not thousands, of dollars, every time he posts -
************************************************************************
rwvpf wpnrrj ibf ijrfer

2. A question about Kernel system call mechanism

3. How to set bash IFS to default?

4. Higher resolution with S3 card

5. Set IFS to non-printable character

6. FTP site for SCO Binaries ?

7. IFS setting

8. philips cd-rom drive

9. remove first 3 chars of a string && set IFS to newline

10. setting IFS to newline in bourne shell

11. Setting IFS ?

12. ksh: Setting IFS to newline

13. Setting of the IFS variable in BASH to omit splitting at tabs and spaces