在Mac OS X zsh上打印后删除尾随的新行

时间:2013-08-13 15:54:27

标签: macos shell line trailing

我正在尝试打印stdin而没有使用cat,grep,awk等后出现的尾随新行(Mac OS X zsh) 不幸的是,echo -n不起作用,它打印出一些奇怪的角色。

你对这件事有什么看法吗? 感谢。

1 个答案:

答案 0 :(得分:2)

来自男士zshoptions:

PROMPT_SP <D>
              Attempt  to  preserve  a  partial  line (i.e. a line that did not end
              with a newline) that would otherwise be covered up by the command prompt
              due to the PROMPT_CR option.  This works by outputting some
              cursor-control characters,
              including a series of spaces, that should make the terminal wrap to the
              next line when a partial line is present (note that this is only 
              successful if your terminal has automatic margins, which is typical).

              When a partial line is preserved, by default you will see an inverse+bold
              character at the end of the partial line:  a "%" for a normal user or a
              "#" for root.  If set, the shell parameter PROMPT_EOL_MARK can be used
              to customize how the end of partial lines are shown.

              NOTE: if the PROMPT_CR option is not set, enabling this option will have
              no effect.  This option is on by default.

将此添加到.zshrc以更改行为。请注意,这是一个设计功能,而不是错误。

export PROMPT_EOL_MARK=''