0

So i read the man echo info. And it says this for the n option.

-n    Do not print the trailing newline character.

I can't wrap my head around what it means.

So if i try it out this is what i get

~ echo -n "12"
12%

I get a % after the argument I passed in.

Without n, stdout will not have %

~ echo "12"
12

Can anyone give practical examples, or a simpler explanation.

4

1 回答 1

3

命令的标准调用echo将打印出传递给的参数echo,后跟换行符。

echo使用标志调用-n只会打印出参数,没有换行符。

因为您%在 shell 中使用了提示符,所以调用echo -n "12", 将打印出12,紧随其后的提示符表示 shell 已准备好接受新输入。

如果没有:它看起来像这样-n

% echo "12"
12
%

并与-n

% echo -n "12"
12%
于 2019-05-14T05:14:50.343 回答