1

I have this:

$ any_command
any_command: command not found

But i need this:

$ any_command

any_command: command not found

What add to PS1?

2 Answers2

2

You can use trap command for this with DEBUG signal:

trap 'echo' DEBUG

This will print a newline before any command output.

$ any_command

bash: any_command: command not found
$

Or:

$ date

Tue Sep 29 17:51:38 EDT 2015
$
anubhava
  • 664,788
  • 59
  • 469
  • 547
  • 1
    Interesting! +1. For those who want to know more, this is documented in `help trap`. – John1024 Sep 29 '15 at 22:11
  • 1
    Glad to know it worked out, [you may mark the answer as accepted by clicking on **tick mark** on top-left of my answer](http://meta.stackexchange.com/a/5235/160242) – anubhava Sep 29 '15 at 22:39
  • This will work, but will run after each command rather than just when prompting. This creates needless overhead. In addition, it may interfere with shell debuggers that rely on the ability to trap DEBUG. – Todd A. Jacobs Sep 30 '15 at 00:18
  • If you seriously believe that I couldn't post an answer based on `PROMPT_COMMAND` or `PS1` then [see this answer](http://stackoverflow.com/questions/27384748/detect-empty-command/27452329#27452329) OR [this answer](http://stackoverflow.com/questions/5687446/bash-custom-ps1-with-nice-working-directory-path/5687619?s=1|5.0168#5687619). For the same reason your answer doesn't solve the stated problem of **inserting an empty line before a command's output**. Another side effect of that approach is that even pressing empty enter causes newline to appear which is not the case with my approach. – anubhava Sep 30 '15 at 06:01
0

PS1 Prompt with Newline

The GNU Bash Manual contains a section on prompting. The newline escape is probably what you're looking for. For example:

export PS1='\n$ '

Alternatively, you can simply add an echo before or after your command. For example:

$ echo; echo foo

foo

Insert Arbitrary Output with PROMPT_COMMAND

You can automate the extra echo (or other screen output) with the Bash shell's PROMPT_COMMAND variable. The PROMPT_COMMAND isn't limited to just prompting, but it can certainly be leveraged to do what you want in this case. For example:

# call echo before issuing PS1
export PROMPT_COMMAND='echo'

# print the equals sign 80 times before issuing PS1
export PROMPT_COMMAND="printf '=%.0s' {1..80}"
Todd A. Jacobs
  • 71,673
  • 14
  • 128
  • 179