bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: using NUL in scripts


From: Stephane Chazelas
Subject: Re: using NUL in scripts
Date: Fri, 28 Sep 2007 01:14:50 +0100
User-agent: Mutt/1.5.16 (2007-06-11)

On Wed, Sep 26, 2007 at 09:04:19PM -0400, Mike Frysinger wrote:
> is it even possible to utilize NUL in scripts ?  or does bash just strip it 
> out ?  for example, trying to work with binary data:
> foo=$(<binary-file)
> echo "${foo}" > new-file
> the "new-file" will be exactly "binary-file" if all NUL bytes are stripped out
> 
> or perhaps i want to take an arg list, append a string, and run a command on 
> it ... but i cant pass it straight as it may be too large, so i need to xargs 
> it ... so i'd do something like:
> echo ${@/%.moo/.foo$'\000'} | xargs -0 rm -f
> but this doesnt work since the $'\000' gets stripped

Note that a NUL can't be passed to an argument to an external
command, nor can an environment variable contain a NUL
character.

And there's nothing the shell can do about it. The NUL character
is the string delimiter in the *system*'s API there.

zsh is the only shell I know of that supports the NUL character,
but it can only be used internally as in shell variables or
arguments to builtin commands. A zsh variable may contain a NUL
byte, but if it gets exported, of course programs execve'ed
won't get what's past the NUL since the envp argument to execve
is an array of NUL terminated strings.

-- 
St├ęphane




reply via email to

[Prev in Thread] Current Thread [Next in Thread]