bash which OR operator to use – pipe v double pipe

| isn’t an OR operator at all. You could use ||, though: This is equivalent to an if: By the way — consider making a habit of using type (a shell builtin) rather than which (an external command). type is both faster and has a better understanding of shell behavior: If you have an ansible command that’s provided by, say, a shell function invoking the real command, which won’t know … Read more

Error handling in Bash

Use a trap! …then, whenever you create a temporary file: and $temp_foo will be deleted on exit, and the current line number will be printed. (set -e will likewise give you exit-on-error behavior, though it comes with serious caveats and weakens code’s predictability and portability). You can either let the trap call error for you (in which case it uses the default … Read more

How to open Emacs inside Bash

Emacs takes many launch options. The one that you are looking for is emacs -nw. This will open Emacs inside the terminal disregarding the DISPLAY environment variable even if it is set. The long form of this flag is emacs –no-window-system. More information about Emacs launch options can be found in the manual.

What is a simple explanation for how pipes work in Bash?

A Unix pipe connects the STDOUT (standard output) file descriptor of the first process to the STDIN (standard input) of the second. What happens then is that when the first process writes to its STDOUT, that output can be immediately read (from STDIN) by the second process. Using multiple pipes is no different than using … Read more

Difference between sh and Bash

What is sh? sh (or the Shell Command Language) is a programming language described by the POSIX standard. It has many implementations (ksh88, Dash, …). Bash can also be considered an implementation of sh (see below). Because sh is a specification, not an implementation, /bin/sh is a symlink (or a hard link) to an actual implementation on most POSIX systems. What is Bash? Bash … Read more