Tag Archives: set

Pipe failed…?

There are times when you want to monitor the exit status through a whole pipeline of chained commands. But the default behavior of Bash is to show the exit status of the right-most (last) command in the pipe. This can a problem, specifically in scripting.

I prefer if the pipeline’s return status is the value of the last (rightmost) command to exit with a non-zero status, OR zero if all commands in the pipeline exit successfully.

This can be achieved by adding the following line to your script:

set -o pipefail

This can also be added to your ~/.bash_profile to make the change permanent.

Posted in Linux | Tagged , , , , , , , , | Leave a comment

Bash hot-keys

Just a quick mentioning of some Bash hot-keys to make your life easier.

I use Vi/Vim as my editor, but prefer the Emacs hot-keys which is default in the Bash shell.

You can actually shift between Vi and Emacs hot-keys by executing:

set -o vi

or

set -o emacs

The following hot-keys all work in Emacs mode:

Key Effect and memory hook
ctrl-l clear the screen, lose all previous output
ctrl-c abort current line (or the running process)
ctrl-r search in history while typing
ctrl-e jump to the end of the line
Posted in Linux | Tagged , , , , , , , | 2 Comments