On 4/26/20 12:27 PM, Thomas de Grivel wrote:
> Hello,
> 
> I was testing some scripting using /bin/sh and I could not find this
> behaviour in the documentation :
> 
>> $ /bin/sh
>> $ echo -n '\n'
>>
>> $
> 
> It seems that ksh even in sh (posix ?) mode does expansion of \n to an
> actual newline.> 
> First is there a way to turn off the \n expansion in simple quotes in /bin/sh 
> ?

You mean placing an additional \ in front of it?
$ echo '\\n'
\n

Or by calling the binary instead of the shell builtin?
$ /bin/echo '\n'
\n

Or by adding -E?
$ echo -E '\n'
\n

Now also note what POSIX itself says[0]:
It is not possible to use echo portably across all POSIX systems unless
both -n (as the first argument) and escape sequences are omitted.
...
New applications are encouraged to use printf instead of echo.
> 
> Second I don't see this feature described neither in man sh nor man
> ksh so is it a known behaviour of ksh ?

from echo(1):
echo does not support any of the backslash character sequences mandated
by XSI.

from ksh(1):
See the print command below for a list of other backslash sequences that
are recognized.
...
By default, certain C escapes are translated.  These include ‘\b’, ‘\f’,
‘\n’, ‘\r’, ‘\t’, ‘\v’, and ‘\0###’ (‘#’ is an octal digit, of which
there may be 0 to 3).
> 
> Thanks a ton,
> 
[0] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/echo.html

Reply via email to