On Thu, Feb 2, 2017 at 10:56 AM, Jyoti B Tenginakai <[email protected]>
wrote:
> HI All,
>
> Thanks for your quick response.
>
> I have tried using the printf instead of echo. But the issue with printf
> is , the behaviour is not consistent with what echo prints for all the
> inputs i.e.
> In my script I am generically using echo for all the options. If I have to
> use printf instead of it should behave consistently .
> if echo * is passed to bash shell, the o/p shows the \t seperated values
> whereas with printf '%s' *, it won't display space separated output. Again
> printf '%s ' # behaviour is different from what echo # shows
>
Yes, it is. You can change the output by using the appropriate "format"
(the '%s' in your example). For example:
echo -n *
could be emulated with:
printf '%s ' * #note the space in the format after the %s
The outputs are not _identical_ because the printf output has a trailing
space, which the echo does not. If you want tab separators, try:
printf '%s\t' *
If you want something which 100.0000% works exactly and identically like
the BASH "echo" builtin, then you are doomed to disappointment. If you want
a replacement for "echo -n", you might try using a function (defined in
~/.bashrc) similar to:
function echo-n() { printf '%s ' "$@" | sed -r 's/ $//'; }
>
> Thanks & Regards
> --Jyoti
>
> --
There’s no obfuscated Perl contest because it’s pointless.
—Jeff Polk
Maranatha! <><
John McKown