Misc


Case sensitivity
  • Bash scripts are case sensitive.
Testing for the existence of a set of files
if ls *.jpg 2> /dev/null | grep -q jpg; then ... fi   # If there are jpg files in the current directory
Shell expansion
*            # Zero or more characters
? # One character
[...] # One character in the specified set (hyphen specifies a range) (leading ^ or ! specifies negation)
{str,str...} # One string in the specified set (comma-separated)

${variable} # Shell variable (braces optional)
${!variable} # Indirect expansion (getting the name of a shell variable from another variable) (braces required)
${variable:=value} # Create and use a shell variable

$(command) # Command substitution (the output of the specified command)
`command` # Command substitution (back quotes)

$((expr)) # Arithmetic expansion (double parentheses)
$[expr] # Arithmetic expansion (square brackets) (does not do tests)
[123]         # 1, 2, or 3
[a-zA-Z0-9] # Alphanumeric character
[^0-9] # Non-numeric character (same as [!0-9])
{one,two} # "one" or "two"

${!P*} # PATH PHP ...
$[12*2] # 24
Misc
  • Quotes are not needed when assigning one variable to another (for strings with blank spaces)
var1="one two three"
var2=$var1
echo $var2 # one two three
  • How to identify what shell you're running in (Bash, Korn, TCSH, ...) 
echo $SHELL

Resources URL: 
notes/bash/resources
Sources URL: 
notes/bash/sources

See Also