Skip to main content

Command Palette

Search for a command to run...

Bash scripting

Updated
2 min readView as Markdown

brackets

tutorial

One of the comment points out the corresponding terminology in man page. Here are the quick ref for man bash: just search for the Terminology and will jump to the section. For example, /Command Substitution jumps to the dollar single parens section.

DescriptionTerminologyExampleComment
( single parens )one of Compound Commands → subshell(cd a;mkdir b)doesn’t modify current shell
$( dollar single parens )Command Substitutionecho $(ls; echo end)also backticks `command`
(( double parens ))one of Compound Commands → arithmetic expression((a=3+4))integer arithmetic, equivalent of let, doesn’t output
$(( dollar double parens ))Arithmetic Expansiona=$((3+4))integer arithmetic, variables inside don’t need dollar sign
[ single brackets ]CONDITIONAL EXPRESSIONSif [ -f file.txt ]; then echo ‘file exists’; fionly use this for POSIX compatibility, requires spaces around brackets
[[ double brackets ]]CONDITIONAL EXPRESSIONS[[ -f file.txt ]]preferred in bash
{ braces }Brace Expansionecho {1..10..3} file{,.bak}convenient for files with same prefix
${ dollar braces }Parameter Expansion${var:-default}a whole lot of features for string manipulation
<( angle parens )Process Substitutioncomm -12 <( sort file1 ) <( sort file2 )VAR=($( COMMAND )) take output and store as array