What is /dev/null 2>&1?

>> /dev/null redirects standard output (stdout) to /dev/null, which discards it. (The >> seems sort of superfluous, since >> means append while > means truncate and write, and either appending to or writing to /dev/null has the same net effect. I usually just use > for that reason.) 2>&1 redirects standard error (2) to standard … Read more

What does $$ mean in the shell?

$$ is the process ID (PID) in bash. Using $$ is a bad idea, because it will usually create a race condition, and allow your shell-script to be subverted by an attacker. See, for example, all these people who created insecure temporary files and had to issue security advisories. Instead, use mktemp. The Linux man … Read more

How can I execute a command stored in a variable?

Unix shells operate a series of transformations on each line of input before executing them. For most shells it looks something like this (taken from the Bash man page): initial word splitting brace expansion tilde expansion parameter, variable and arithmetic expansion command substitution secondary word splitting path expansion (aka globbing) quote removal Using $cmd directly … Read more