Subject: Re: This has GOT to be a bug in ksh...
To: NetBSD User's Discussion List <netbsd-users@NetBSD.ORG>
From: David Laight <david@l8s.co.uk>
List: netbsd-users
Date: 06/19/2002 19:13:41
> 
> 	$ printf "%b" "foo\nbar\n"
> 	foo
> 	bar
> 	$ 
> 
> What the "opposite" of "%b" would do would be to translate unprintable
> characters back into visible escape sequences just as "vis -ctl" does,
> so hopefully the following example would work, assuming %B is the
> functional opposite of the currently implemented %b:
> 
> 	$ printf "%B\n" "$(printf "%b" "foo\tbar\t\n")"
> 	foo\tbar\t
> 	$ 

I've been busy...

$ pwd
/usr/bsd-current/obj/usr.bin/printf
$ ./printf "%B\n" "$(./printf "%b" "foo\tbar\t\n")"
foo\tbar\t
$ ./printf "%B\n" "$(./printf "%b" "foo\nbar\n")"  
foo\nbar
$ 

FWIW the shell(s) strip trailing newlines from all $(...)
substitutions regardless of whether they are quoted and
the value of IFS - this isn't completely helpful!

also:

$ ./printf "'%-12.5b'\n" "foo bar"
'foo b       '
$ printf "'%-12.5b'\n" "foo bar"  
printf: %-12.5b: invalid directive

Now I think this is a posix non-conformity.....

Anyone want the fix?  go to www.l8s.co.uk then netbsd/printf.c

	David

-- 
David Laight: david@l8s.co.uk