[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: echo -n
From: |
Stephane Chazelas |
Subject: |
Re: echo -n |
Date: |
Thu, 2 Feb 2017 17:18:47 +0000 |
User-agent: |
Mutt/1.5.24 (2015-08-30) |
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
- Re: echo -n, (continued)
- Re: echo -n, John McKown, 2017/02/02
- Re: echo -n, Pierre Gaston, 2017/02/02
- Re: echo -n, Jyoti B Tenginakai, 2017/02/02
- Re: echo -n, Greg Wooledge, 2017/02/02
- Re: echo -n, John McKown, 2017/02/02
- Re: echo -n, Chet Ramey, 2017/02/02
- Re: echo -n, Jyoti B Tenginakai, 2017/02/05
- Re: echo -n, Clark Wang, 2017/02/06
- Re: echo -n, Peter & Kelly Passchier, 2017/02/06
- Re: echo -n, Stephane Chazelas, 2017/02/06
- Re: echo -n,
Stephane Chazelas <=