2017-02-02 22:26:22 +0530, Jyoti B Tenginakai:
[...]
> 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
[...]

See also:

https://unix.stackexchange.com/questions/65803/why-is-printf-better-than-echo


In bash, you can define:

puts() {
  local IFS=' '
  printf '%s\n' "$*"
}

as a function that outputs its arguments separated by spaces and
terminated with a newline character.

POSIXly:

puts() (
  IFS=' '
  printf '%s\n' "$*"
)

With with some shells like bash, that implies an additional
fork.

Note hat ksh and zsh also have:

print -r -- *

for that.

-- 
Stephane


Reply via email to