Re: find -print0 confusing me



2007-02-21, 13:22(-06), Charles Russell:
Why does the ascii nul character not appear in the string when it is
created by a backquote? (See below.) I am trying to figure out how to
handle spaces in pathnames.

#!/usr/bin/sh
echo "straight call to find"
# make ascii nul visible by swapping for @
find . -type d -name '*' -print0 | tr "\0" @
echo
echo "calling in backquotes"
echo `find . -type d -name '*' -print0 `| tr "\0" @

output:

$ puzl.sh
straight call to find
.@./spl it@./spl it
calling in backquotes
../spl it./spl it2

The NUL byte is the string terminator. For instance, the list of
arguments passed to a command is a list of NUL terminated
strings. So the NUL byte can't be passed in an argument to a
command.

Some shells like zsh (and possibly recent versions of ksh93)
are able to pass NUL characters to their builtin commands (and
only to the builtin ones).

The code above would have /worked/ with zsh.

--
Stéphane
.



Relevant Pages

  • Re: Can I add myself to Administrators group of all PCs when I log
    ... @echo Choose the domain for this PC from the menu below... ... if errorlevel = 11 goto CFEWC ... net localgroup administrators "ndhq\baseline managers" /add> nul ...
    (microsoft.public.windows.server.scripting)
  • Re: Batch file help
    ... copy file1.txt f:\file2.txt 1> NUL ... On win2K if I have an error, such as not enough room on f:, ... @echo off ... echo Insufficient space on drive F:. ...
    (microsoft.public.windowsxp.general)
  • Re: Batch file help
    ... On win2K if I have an error, such as not enough room on f:, ... to NUL:. ... @echo off ... echo Insufficient space on drive F:. ...
    (microsoft.public.windowsxp.general)
  • Re: Batch file help
    ... On win2K if I have an error, such as not enough room on f:, ... to NUL:. ... @echo off ... echo Insufficient space on drive F:. ...
    (microsoft.public.windowsxp.general)
  • Re: find -print0 confusing me
    ... Why does the ascii nul character not appear in the string when it is ... echo, print and printf do. ... : echo "calling in backquotes" ...
    (comp.unix.shell)

Quantcast