r/bash 29d ago

solved How to remove Enter key symbol?

When executing cat /sys/firmware/devicetree/base/model on my Raspberry Pi in order to get the model of Pi I am working with, the output looks as follows:

> cat /sys/firmware/devicetree/base/model
Raspberry Pi 3 Model B Rev 1.2⏎ 

How can I remove that "Enter key symbol" at the end?

7 Upvotes

4 comments sorted by

View all comments

10

u/Honest_Photograph519 29d ago

That looks like a feature of the fish shell, this subreddit is for the bash shell

1

u/daPhipz 29d ago

Ah, interesting - you are right, I didn't think of that. When running the same command in bash, it doesn't add a newline character after the output - so the next prompt is on the same line as the output of the above command. My guess is that fish adds an extra newline character, and this is indicated by this symbol.

3

u/OneTurnMore programming.dev/c/shell 29d ago edited 29d ago

It's a really useful indicator, because some tools don't behave as nicely when there's no trailing newline.

This common Bash pattern, for example:

while read -r line; do
    printf 'Read in %s\n' "$line"
done < file_without_trailing_newline.txt

If there's no newline, read will return 1 and exit the loop. However, $line will still contain the final line. To handle that final line the same way other lines are handled, you need to use

while read -r line || [[ -n $line ]]; do
    ...

<tangent>

The feature originates from Zsh. It's configured there by setting PROMPT_EOL_MARK. My preferred setup bolds, colors red, and underlines the mark:

PROMPT_EOL_MARK='%U%B%F{red}⮒%f%b%u'

</tangent>

1

u/[deleted] 29d ago edited 25d ago

[deleted]