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

Re: Prompting \n



T o n g wrote:
> It's a well known problem to show/prompt messages with embedded \n under 
> *nix. 

Well known but obsolete now.  If you need to use control sequences
such as \n or others then do not use echo at all but use printf
instead.

> - Unix Power Tools recommend a way to define $echo according to different 
> environments, but I found that ceased to work a while ago. 

The Unix Power Tools book is a wonderful tome of knowledge but
depending upon your edition was published quite a few years ago.  Most
importantly for this case it predates the POSIX 'printf' command which
was created specifically to address the echo with format sequences
problem.

> - the printf can handle \n, but I found it produce much more trouble. 

Uhm...  Such as?  Really, printf is the right tool to use.

> So, I'm wondering what's the current solution to show/prompt messages 
> with embedded \n?

Use printf.  What problems are you having with it?

  $ printf "Hello world!\n"

Prior to using printf many of us would drop back to using awk's
printf.  That is still available to you.

  $ awk 'BEGIN{printf("Hello world!\n");exit}'

Bob

Attachment: signature.asc
Description: Digital signature


Reply to: