How to determine if a bash variable is empty?
This will return true if a variable is unset or set to the empty string (“”). if [ -z “${VAR}” ];
This will return true if a variable is unset or set to the empty string (“”). if [ -z “${VAR}” ];
If you are on a OS X, this probably has nothing to do with the sed command. On the OSX version of sed, the -i option expects an extension argument so your command is actually parsed as the extension argument and the file path is interpreted as the command code. Try adding the -e argument explicitly and giving ” as argument to -i: See this.
I think this is precisely what you are asking for: http://www.bashcookbook.com/bashinfo/source/bash-4.0/examples/scripts/timeout3
You can use this syntax:
| 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
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
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.
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
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
head takes the first lines from a file, and the -n parameter can be used to specify how many lines should be extracted: