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

Re: Prompting \n



On Sat, 24 Dec 2011 19:18:17 -0700, Bob Proulx wrote:

>> 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"

Thanks for your explanation, Bob.

What I didn't make clear in the OP was that, I was actually looking for a 
general purpose command that can show whatever messages thrown to it, 
including the common backslash escapes. echo -e does a good job, but 
printf will choke on any of its control characters, e.g., %.

Today, I just found that printf cannot be used to show whatever the 
command line is. Here is an example:

  set -- command -opt param params...

  echo='echo -e'

  $ $echo "\n> $@\n"

  > command -opt param params...

So far so good. Now try printf:

  $ printf "\n> $@\n"

  > command

What's happening? why printf chokes on '-'?

BTW, the reason that I gave up 'echo -e' was that it started to 
mysteriously output that "-e " in front of the messages I wanted to show 
in my /bin/sh scripts. I still haven't figure out why yet. 

Thanks

-- 
Tong (remove underscore(s) to reply)
  http://xpt.sourceforge.net/techdocs/
  http://xpt.sourceforge.net/tools/


Reply to: