Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add newline after output of every bash command

Tags:

bash

dotfiles

I'm in the process of customizing my terminal.

Currently, I have the following:

before

What I want is a newline after the output of every command, like this:

after

The only way I have been able to accomplish something close to this is by adding a newline at the beginning of my PS1. This works, but it annoys the hell out of me that the first time I open up a bash prompt, there is a newline above the very first line. Is there any other way to accomplish this?

like image 222
bitpshr Avatar asked Oct 26 '13 17:10

bitpshr


People also ask

How to add a newline to the output of a shell script?

As you are running from inside a shell script, just add echo after each awk command i.e. in between the commands you want to get separate outputs. echo adds a newline. For example: Append printf " " at the end of each awk action {}. printf " " will print a newline. Show activity on this post.

How to add a new line in a sentence in Linux?

In many cases, we need to add a new line in a sentence to format our output. In this tutorial, we’ll explore some Linux commands for printing a new line character ( ) in a sentence. 2. Using echo The echo command is one of the most commonly used Linux commands for printing to standard output:

How do I add a newline to the output of AWK?

As you are running from inside a shell script, just add echo after each awk command i.e. in between the commands you want to get separate outputs. echo adds a newline. For example: Append printf " " at the end of each awk action {}. printf " " will print a newline.

How do I echo a line in Linux?

Using echo The echo command is one of the most commonly used Linux commands for printing to standard output: By default, echo considers as a regular part of the input string. So, to enable the echo command to interpret the new line character, we should use the -e option:


1 Answers

One approach using printf:

$ printf '%s\n' * $'\n'

or better (for every command):

$ PROMPT_COMMAND="echo"
$ ls

From man bash :

If PROMPT_COMMAND is set and has a non-null value, then the value is executed just as if it had been typed on the command line.

like image 175
Gilles Quenot Avatar answered Sep 22 '22 16:09

Gilles Quenot