'Remove percentage printf and shell

I'm beginning to learn the shell commands. And I don't know how to remove the percent character in the end.

Example: printf poo shows poo%

I'm on mac and I use oh my zsh!



Solution 1:[1]

The printf command doesn't start a new line after the output. The % character you see is from zsh. It indicates that the preceding line is potentially incomplete (because there was no terminating newline).

To fix this, try printf 'poo\n' or echo poo (echo adds a newline by default).

Solution 2:[2]

The percentage sign (%) you see at the end is an absence of a trailing newline character, or in other words, an incomplete line.

Solution:

You can remove the percentage sign by appending core code with ; echo.

Example:

# Issue
$ printf "foo"
poo%

# Solution
$ printf "foo"; echo
foo

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 melpomene
Solution 2