bash filename - Runs script |
Shebang - "#!bin/bash" - First line of bash script. Tells script what binary to use |
./filename - Also runs script |
# - Creates a comment |
echo ${variable} - Prints variable |
hello_int = 1 - Treats "1" as a string |
Use UPPERCASE for constant variables |
Use lowercase_with_underscores for regular variables |
echo $(( ${hello_int} + 1 )) - Treats hello_int as an integer and prints 2 |
mktemp - Creates temporary random file |
test - Denoted by "[[ condition ]]" tests the condition |
bash -x - Prints commands and their arguments |
ps -f - Copies the current shell in the fork |
exit value - Exits the script with value exit code |
-n variable - decides if variable is not empty |
-z variable - Decides if variable is empty |
$? - Stands for the previous exit code |
$# - Stands for the number of arguments passed |
[[ $# -ne 2 ]] - Evaluates to true if the number of arguments is not equal to 2 |
-f filename - Determines if filename is a file |
-d directoryName - Determines if directoryName is a directory |
$1, $2, $3 - Refers to the first, second, and third arguments |
-eq - means == |
-lt - Means < |
-le - Means <= |
-gt - Means > |
-ge - Means >= |
dirname - Prints directory name of of argument |
sleep value - Forces the script to wait value seconds |
while [[ condition ]]; do stuff; done |
if [[ condition ]]; do stuff; fi |
until [[ condition ]]; do stuff; done |
words="house dogs telephone dog" - Declares words array |
for word in ${words} - traverses each element in array |
for counter in {1..10} - Loops 10 times |
for ((;;)) - Is infinite for loop |
break - exits loop body |
for ((counter=1; counter -le 10; counter++)) - Loops 10 times |
${array[I]} - Indexes array |
${array[]} - References the whole array. Can also use @* |
declare -A array - declares associative array |
myassocarray=([apple]="red" [banana]="yellow") - Creates associative array |
${myassocarray[banana]} - References bananas value in the array |
unset array[I] - Deletes the I index |
unset array - Deletes the array |
${#array} - Outputs the length of the array |
alias ll = 'ls -l' - Creates the ll command as an alias |
home() { do stuff ; } Creates the home function |
return - defaults to the previous exit value |
local - Creates local variable within function |
cut - Cuts away parts of the output |
Created By
Metadata
Favourited By
Comments
adamsbra, 14:22 14 Feb 20
Thanks bro this cheat sheet helped me figure out how to rm -rf my internal demons 10/10 better than an exorcism.
mmorykan, 14:23 14 Feb 20
Thanks for the support!
Add a Comment
Related Cheat Sheets