【发布时间】:2018-06-21 20:58:48
【问题描述】:
以下 hello-world 程序在打印字符串的末尾显示一个 % 符号。为什么会这样?如何删除?
这是我的程序:
section .data
msg db "hello, world!"
section .text
global _start
_start:
mov rax, 1 ; syscall 1 (write)
mov rdi, 1 ; arg 1 = 1 (stdout)
mov rsi, msg ; arg 2 = msg ("hello, world!")
mov rdx, 13 ; arg 3 = 13 (char count)
syscall ; call write
mov rax, 60 ; syscall 60 (exit)
mov rdi, 0 ; arg 1 = 0 (OK)
syscall ; call exit
这是我运行可执行文件时的输出:hello, world!%
提前致谢。
编辑:这似乎是由 zsh 引起的(在 bash 中不可重现)。问题是为什么会发生这种情况以及如何解决它。
【问题讨论】:
-
原来是我的外壳。它发生在 zsh 而不是 bash 上。
-
但是为什么这会发生在 zsh 上呢?我该如何解决?
-
做了更多测试,结果当打印的字符串不以换行符结尾时,zsh 正在插入
%,后跟换行符,而 bash 不这样做。 -
参见 Why ZSH ends a line with a highlighted percent symbol?(TL;DR - 这是一个 zsh 功能,可以使用
unsetopt prompt_cr prompt_sp禁用)。
标签: linux nasm x86-64 zsh system-calls