Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to insert a separator after the command in a prompt? This is an example:

~/Desktop: ls -al
total 80
drwx------+  6 eddie  staff   204B Apr 29 16:57 .
drwxr-xr-x+ 54 eddie  staff   1.8K Apr 30 10:54 ..


Specifically I want to add the --------- part after issuing a command to easier distinguish the command from the result

share|improve this question
For every command? What shell? – jordanm Apr 30 '13 at 18:30
Ideally for every command that actually has an output. zsh – Eddie Monge Jr May 1 '13 at 19:26
up vote 8 down vote accepted

In zsh, you can define the hook function preexec to echo a specified string before every command is executed.

In bash, you could use the DEBUG trap to set up a preexec hook to do the same.

You would define a preexec() function something like this:

preexec () { echo "-------------------------------"; }
preexec_invoke_exec () {
    [ -n "$COMP_LINE" ] && return  # do nothing if completing
trap 'preexec_invoke_exec' DEBUG

See more details at Does bash have a hook that is run before executing a command?

I don't think this works in all versions of bash though. On my old Ubuntu server, running bash 3.2.39(1), help trap says

If a SIGNAL_SPEC is DEBUG, ARG is executed after every simple command.

On another server, running bash 4.1.2(1), it says

If a SIGNAL_SPEC is DEBUG, ARG is executed before every simple command.

which is what we need. So make sure that in your version of bash, help trap says "before every simple command."

share|improve this answer

If you're using bash or ksh for your shell, you can create a function in one of your dotfiles (.profile, .bash_profile, etc) like so:

function hr {
    echo "--------------------------------------------------------------------------------"

Then, you can prepend it to commands whenever you want that separator using && or ; as command separators. As in:

bash-[534]$ hr && ls
ddtool_23.jnlp  prtconf-pv


bash-[536]$ hr ; ls -la
total 36K
drwxr-xr-x  2 tim staff    4 2012-12-06 15:02 ./
drwxr-xr-x 46 tim staff  134 2013-04-30 14:59 ../
-rw-------  1 tim staff 2.7K 2012-12-06 15:00 ddtool_23.jnlp
-rw-r--r--  1 tim staff  24K 2012-12-06 15:02 prtconf-pv

I do this. I have a second function that prints a thicker separator, as well.

function hr2 {
    echo "================================================================================"

I often use these functions in shell scripts to provide separation to different parts of the scripts, such as hr2 between main tasks, and hr between items in a loop statement. It makes reading script output much easier.

share|improve this answer
Why not function hr { echo '---…'; "$@"; } instead? Then you can use it without && or ; too: hr ls -la. By the way, an even thicker separator: figlet -- '---…'. – manatwork May 1 '13 at 10:15
mostly because i never thought of that. thanks for the idea. :) – Tim Kennedy May 1 '13 at 15:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.