{
    "id": "bash_cheat_sheet",
    "name": "Bash",
    "description": "Bash is a Unix shell and command language written by Brian Fox as a replacement for the Bourne shell",
    "metadata": {
        "sourceName": "Bash Reference Manual",
        "sourceUrl": "https://www.gnu.org/software/bash/"
    },
    "aliases": [
        "shell",
        "shell language",
        "posix shell",
        "sh"
    ],
    "template_type": "code",
    "section_order": [
        "Lingo",
        "Shortcuts",
        "Special Variables",
        "Standard File Descriptors",
        "Arithmetic Operators",
        "IO Redirection",
        "Expansion And Other Operators",
        "Conditionals",
        "Loops",
        "Exit Statuses",
        "Auto-Completion",
        "Misc",
        "TCP/UDP Sockets"
    ],
    "sections": {
        "Lingo": [
            {
                "key": "C",
                "val": "Ctrl"
            },
            {
                "key": "M",
                "val": "Meta Key (Alt or ESC)"
            }
        ],
        "Shortcuts": [
            {
                "key": "C-c",
                "val": "Interrupt running process"
            },
            {
                "key": "C-z",
                "val": "Suspend running process"
            },
            {
                "key": "C-d",
                "val": "Exit from current shell"
            },
            {
                "key": "C-l",
                "val": "Clear Screen"
            },
            {
                "key": "C-a",
                "val": "Move at the start of the line"
            },
            {
                "key": "C-e",
                "val": "Move at the end of the line"
            },
            {
                "key": "M-←",
                "val": "Move backward by a word"
            },
            {
                "key": "M-b",
                "val": "Move backward by a word (alternative)"
            },
            {
                "key": "M-→",
                "val": "Move forward by a word"
            },
            {
                "key": "M-f",
                "val": "Move forward by a word (alternative)"
            },
            {
                "key": "[C-x], [C-x]",
                "val": "Move cursor between start of line and current position"
            },
            {
                "key": "M-t",
                "val": "Swap the last two words before the cursor"
            },
            {
                "key": "C-t",
                "val": "Swap the last two characters before the cursor"
            },
            {
                "key": "M-Backspace",
                "val": "Delete a word (backward)"
            },
            {
                "key": "C-w",
                "val": "Delete a word (backward) (alternative)"
            },
            {
                "key": "M-d",
                "val": "Delete a word (forward)"
            },
            {
                "key": "C-h",
                "val": "Delete one character backward (same as Backspace)"
            },
            {
                "key": "C-k",
                "val": "Kill from cursor to the end of line"
            },
            {
                "key": "C-u",
                "val": "Kill from cursor to the beginning of line"
            },
            {
                "key": "M-u",
                "val": "Upper-case from cursor to the end of word"
            },
            {
                "key": "M-l",
                "val": "Lower-case from cursor to the end of word"
            },
            {
                "key": "M-c",
                "val": "Capitalize word (from cursor position)"
            },
            {
                "key": "C-y",
                "val": "Paste"
            },
            {
                "key": "C-_",
                "val": "Undo"
            },
            {
                "key": "M-r",
                "val": "Revert to original command (before editing it)"
            },
            {
                "key": "C-p",
                "val": "Get previous command"
            },
            {
                "key": "C-n",
                "val": "Get next command"
            },
            {
                "key": "[C-r], [<pattern>]",
                "val": "Search previous command containing <pattern>"
            },
            {
                "key": "M-.",
                "val": "Insert last argument of last command"
            },
            {
                "key": "[M-<N>], [C-M-y]",
                "val": "Get Nth argument of previous command (N=0 gives the command)"
            },
            {
                "key": "M-<",
                "val": "Insert oldest command from history"
            },
            {
                "key": "[C-x], [C-v]",
                "val": "Show bash version"
            },
            {
                "key": "[C-x], [C-e]",
                "val": "Edit current line with ${EDITOR}"
            }
        ],
        "Special Variables": [
            {
                "key": "!$",
                "val": "Last argument of last command"
            },
            {
                "key": "$<N>",
                "val": "Nth argument of current process (positional parameter)"
            },
            {
                "key": "$#",
                "val": "Number of arguments given to current process"
            },
            {
                "key": "$@",
                "val": "Command line arguments for current process"
            },
            {
                "key": "$*",
                "val": "Without quotes, same as '$@'"
            },
            {
                "key": "\"$*\"",
                "val": "Command line arguments for current process, expanded to a single argument"
            },
            {
                "key": "$0",
                "val": "The name of the shell program"
            },
            {
                "key": "$?",
                "val": "Exit code of previous command"
            },
            {
                "key": "$$",
                "val": "PID of current shell or script"
            },
            {
                "key": ":",
                "val": "Dummy placeholder (produces no output)"
            },
            {
                "key": "!-<N>",
                "val": "Execute Nth command from history"
            },
            {
                "key": "!!",
                "val": "Execute last command"
            },
            {
                "key": "!<string>",
                "val": "Execute last command starting with <string>"
            }
        ],
         "Standard File Descriptors": [
            {
                "key": "0",
                "val": "stdin"
            },
            {
                "key": "1",
                "val": "stdout"
            },
            {
                "key": "2",
                "val": "stderr"
            }
        ],
        "TCP/UDP Sockets": [
            {
                "key": "cat < /dev/tcp/<hostname>/<port>",
                "val": "Open a TCP socket to <hostname> at <port> and write the contents of stdin"
            },
            {
                "key": "cat < /dev/udp/<hostname>/<port>",
                "val": "Open a UDP socket to <hostname> at <port> and write the contents of stdin"
            }
        ],
        "Arithmetic Operators": [
            {
                "key": "+",
                "val": "Addition"
            },
            {
                "key": "-",
                "val": "Subtraction"
            },
            {
                "key": "++",
                "val": "Increment"
            },
            {
                "key": "--",
                "val": "Decrement"
            },
            {
                "key": "*",
                "val": "Multiplication"
            },
            {
                "key": "/",
                "val": "Division"
            },
            {
                "key": "%",
                "val": "Modulo"
            },
            {
                "key": "**",
                "val": "Exponentiation"
            },
            {
                "key": "<<",
                "val": "Bit-shift left"
            },
            {
                "key": ">>",
                "val": "Bit-shift right"
            },
            {
                "key": "<",
                "val": "Comparison (less than)"
            },
            {
                "key": "-lt",
                "val": "Comparison (less than) (alternative)"
            },
            {
                "key": "<=",
                "val": "Comparison (less than or equal)"
            },
            {
                "key": "-le",
                "val": "Comparison (less than or equal) (alternative)"
            },
            {
                "key": ">",
                "val": "Comparison (greater than)"
            },
            {
                "key": "-gt",
                "val": "Comparison (greater than) (alternative)"
            },
            {
                "key": ">=",
                "val": "Comparison (greater than or equal)"
            },
            {
                "key": "-ge",
                "val": "Comparison (greater than or equal) (alternative)"
            },
            {
                "key": "==",
                "val": "Comparison (equal)"
            },
            {
                "key": "!=",
                "val": "Comparison (not equal)"
            },
            {
                "key": "&",
                "val": "Bitwise AND"
            },
            {
                "key": "^",
                "val": "Bitwise exclusive OR"
            },
            {
                "key": "|",
                "val": "Bitwise OR"
            },
            {
                "key": "&&",
                "val": "Logical AND"
            },
            {
                "key": "||",
                "val": "Logical OR"
            }
        ],
        "IO Redirection": [
            {
                "key": "cmd > file",
                "val": "Send cmd output to file (overwrite)"
            },
            {
                "key": "cmd >> file",
                "val": "Send cmd output to file (append)"
            },
            {
                "key": "cmd < file",
                "val": "Contents of file are passed to cmd's stdin"
            },
            {
                "key": "cmd1 | cmd2",
                "val": "Output of cmd1 is passed to cmd2's stdin"
            },
            {
                "key": "cmd &> file",
                "val": "Redirect both stdout and stderr to file (overwrite)"
            },
            {
                "key": "cmd &>> file",
                "val": "Redirect both stdout and stderr to file (append)"
            },
            {
                "key": "cmd >&n",
                "val": "Send cmd's stdout to file descriptor n"
            },
            {
                "key": "cmd m>&n",
                "val": "Same as above except that output that would normally go to file descriptor m, will also go to n"
            },
            {
                "key": "cmd <&n",
                "val": "File descriptor n becomes stdin for cmd"
            },
            {
                "key": "cmd m<&n",
                "val": "Same as above except that stdin that would normally come from file descriptor m, will now come from n"
            },
            {
                "key": "cmd >&-",
                "val": "Close stdout"
            },
            {
                "key": "cmd <&-",
                "val": "Close stdin"
            }
        ],
        "Expansion And Other Operators": [
            {
                "key": "${var:pos}",
                "val": "Extracts substring from var at pos"
            },
            {
                "key": "${var:pos:len}",
                "val": "Extracts len characters of substring from var at pos"
            },
            {
                "key": "${var:-val}",
                "val": "If $var exists and isn't NULL, return its value; otherwise return val"
            },
            {
                "key": "${var:=val}",
                "val": "If $var exists and isn't NULL, return its value; otherwise set it to val and then return its value"
            },
            {
                "key": "${var:?val}",
                "val": "If $var exists and isn't NULL, return its value; otherwise return 'var: val' and abort"
            },
            {
                "key": "${var:?}",
                "val": "If $var exists and isn't NULL, return its value; otherwise return 'var: parameter null or not set' and abort"
            },
            {
                "key": "${var:+val}",
                "val": "If $var exists and isn't NULL, return val; otherwise return NULL"
            },
            {
                "key": "$((...))",
                "val": "Arithmetic Expansion"
            },
            {
                "key": "${#var}",
                "val": "String length operator"
            },
            {
                "key": "${str#substr}",
                "val": "Deletes shortest match of substr from front of str"
            },
            {
                "key": "${str##substr}",
                "val": "Deletes longest match of substr from front of str"
            },
            {
                "key": "${str%substr}",
                "val": "Deletes shortest match of substr from back of str"
            },
            {
                "key": "${str%%substr}",
                "val": "Deletes longest match of substr from back of str"
            },
            {
                "key": "${str/substr/val}",
                "val": "Replace first match of substr with val"
            },
            {
                "key": "${str//substr/val}",
                "val": "Replace all matches of substr with val"
            },
            {
                "key": "${str/#substr/val}",
                "val": "If $substr matches front end of str, substitute val for substr"
            },
            {
                "key": "${str/%substr/val}",
                "val": "If $substr matches back end of str, substitute val for substr"
            },
            {
                "key": "${str^substr}",
                "val": "Upper-case of first match of substr. An empty pattern selects first char."
            },
            {
                "key": "${str^^substr}",
                "val": "Upper-case of all matches of substr. An empty pattern selects the whole string."
            },
            {
                "key": "${str,substr}",
                "val": "Lower-case first match of substr. An empty pattern selects first char."
            },
            {
                "key": "${str,,substr}",
                "val": "Lower-case all matches of substr. An empty pattern selects the whole string."
            }
        ],
        "Conditionals": [
            {
                "key": "if \\[$hello == \"world\"\\] ; then ...; fi",
                "val": "If statement"
            },
            {
                "key": "elif \\[$hello == \"world\"\\] ; then",
                "val": "Else if statement"
            },
            {
                "key": "else",
                "val": "Else statement"
            },
            {
                "key": "fi",
                "val": "End if statement"
            },
            {
                "key": "case \"$hello\" in",
                "val": "Case statement"
            },
            {
                "key": "a) echo world ;;",
                "val": "Case entry \"a\""
            },
            {
                "key": "*) echo default ;;",
                "val": "Default case entry (matches everything)"
            },
            {
                "key": "esac",
                "val": "End case statement"
            }
        ],
        "Loops": [
            {
                "key": "for ((i = 1; i <= 10; i++)) ; do \\[expressions\\] done",
                "val": "For loop running 10 times"
            },
            {
                "key": "for i in $list ; do \\[expressions\\] done",
                "val": "For loop being executed for every item in $list"
            },
            {
                "key": "while (i <= 10) ; do \\[expressions\\] done",
                "val": "While loop"
            },
            {
                "key": "done",
                "val": "End loop"
            }
        ],
        "Exit Statuses": [
            {
                "key": "0",
                "val": "Success"
            },
            {
                "key": "!=0",
                "val": "Failure"
            }
        ],
        "Auto-Completion": [
            {
                "key": "TAB",
                "val": "Auto-complete (hit twice when ambiguous)"
            },
            {
                "key": "[~], [TAB] [TAB]",
                "val": "Display all users from /etc/passwd"
            },
            {
                "key": "[$], [TAB] [TAB]",
                "val": "Display all system variables"
            },
            {
                "key": "[<string>], [M-/]",
                "val": "Auto-complete/display files and directories starting with <string>"
            },
            {
                "key": "[<string>], [M-?]",
                "val": "Display commands starting with <string>"
            },
            {
                "key": "M-*",
                "val": "Insert all possible completions"
            }
        ],
        "Misc": [
            {
                "key": "a=$(cmd)",
                "val": "$a now holds cmd's output"
            },
            {
                "key": "a=`cmd`",
                "val": "$a now holds cmd's output (alternative)"
            },
            {
                "key": "cmd &",
                "val": "Execute cmd in the background (fork)"
            }
        ]
    }
}