Re: bash question ... echo subtleties



On Sun, 09 Dec 2007 19:45:30 +0100, mallin.shetland wrote:
[...]
I like a '-' states 'end of argument', GNU prefers '--',
echo ignore both these conventions.

GNU and POSIX and every Unix. "-" states the "end of arguments"
only in a few utilities (including sh where "--" is supported as
well).

"-" is more often used to refer to stdin or stdout when used in
place of a file argument used for input or output respectively
(which is a pain as it means you need to take that into account
as in):

case $file1 in
(-*) file1=./$file1;;
esac
case $file2 in
(-*) file2=./$file2;;
esac
paste "$file1" "$file2"

Mark Hobley scrisse:

I'll leave you to decide whether that is a bug or a feature (I say bug).

I think it is a POSIX feature. :P
No I *REALLY* think both 'echo -e ...' and 'echo -n ...' are
great mistakes but it is too late to do anything.
[...]

No, POSIX allows "-n" and says the behavior is unspecified if
it's provided. This is so that BSD shells are still POSIX
conformant, but of course that means you shouldn't use echo -n
in POSIX scripts. Other options like "-e" are not allowed by
POSIX and in that bash is not POSIX conformant. This is
intentional and claimed by GNU. "echo -n" is in the GNU standard
and you'll find that GNU doesn't discourage its usage.

Note that the Unix spec (SusV3 with XSI option) goes further in
that no option are supported (echo -n should output "-n<LF>")
but the Unix echo is also meant to expand the \n, \t, \f...
sequences, so that it can't be used reliably to output arbitrary
strings either.

--
Stephane
.



Relevant Pages

  • Re: Ubuntu sh cannot echo backslash bug
    ... the POSIX standard as any other shell. ... Shells that depend on the portability of echo are the broken thing here. ... that's even what POSIX recommends. ...
    (comp.unix.shell)
  • Re: read, printf, and special chars
    ... echo is one of the least reliable and least portable commands. ... A POSIX conformant echo (UNIX is POSIX, ... separated by one space and terminated by a newline character as ...
    (comp.unix.shell)
  • Re: copy a directory recursively without data/files
    ... It's what POSIX requires, and what most shells do. ... echo $0 $1 ... returns its invocation name and the first argument, ...
    (comp.unix.shell)
  • Re: echoing first 500 bytes of file to screen
    ... I can use 'cat' to echo all of a file ... Everything that uses a long option is not POSIX has POSIX ... Note that head -500c will output the first 500 bytes of the ...
    (comp.unix.shell)
  • Re: tar -cvfX save.tar foo ./dirtosave/..
    ... >>my time counting characters and otherwise imagining abstractions given ... GNU `tar' should be able to ... But, being strictly POSIX, the limit was still 100 characters. ...
    (comp.os.linux.misc)