Skip to content

Instantly share code, notes, and snippets.

@a1mzone
Last active July 13, 2020 08:32
Show Gist options
  • Save a1mzone/6769f69b8d1c5a4eb24139cf2f8ddde1 to your computer and use it in GitHub Desktop.
Save a1mzone/6769f69b8d1c5a4eb24139cf2f8ddde1 to your computer and use it in GitHub Desktop.
Cheatsheet - BASH

BASH

Find Terminal

ps | grep $$
which 

!#/bin/terminal

Variables

NAME_1="ZAK"
echo "Name is: \$NAME_1"            # \ esc special character
echo "Name is: ${NAME_1}COETZEE"    # ${} encapsulate avoid ambiguity

LIST=`ls`
HOME_LIST=$(ls -la ~/)

Arguments

./test.sh arg1 arg2
$1  arg1
$2  arg2
$0  file
$#  number of Arguments
$@  argument list, space seperated

Arrays

my_arr=(item1 item2 item3)
my_arr[0]=item1_value
echo ${#my_arr[@]}  

Decisions

if [ "$NAME" = "value1" ]; then
    echo "true"
elif [ "$NAME" = "value2"]; then
    echo "true for elif"
else
    echo "false"
fi

Operators

=
==
!= 
-z 

Loops

for arg in [list]
do
    commands
done

Functions

function name_1 {
    echo "func1"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment