Bash

#!/bin/bash

echo "Hello world"
echo "This is the first command"; echo "This is the second command"

variable="Some string"

echo "$variable" # Some stringhello
echo '$variable' # $variable

echo "${variable}"

echo "${variable/Some/A}" # A string -> Substitutes the first occurence of Some with A 

length=7
echo "{variable:0:length}"

echo "{variable: -5}" # this is will return last 5 characters

other_variable="variable"
echo ${!other_variable}

echo "${foo: "DefaultValueIfFoolsIsMissingOrEmpty}"

array=(one two three four five six)

echo "{array[0]}"
echo "{array[1]}"
echo "{array[@]}" # print all elements of the array
echo "{#array[@]}" # print the size of the array
echo "{#array[2]}" # print the number of characters in array[2]
echo "{array[@]:3:2}" # print 2 elements starting from fourth

for item in "${array[@]}"; do
    echo "$item"
done

echo "Last program's return value: $?"
echo "Script's PID: $"
echo "Number of arguements passed to the script: $#"
echo "All arguements passed to script: $@"
echo "Script's arguements seperated into differnet variables: $1 $2"

echo {1..10}
echo {a..z}

echo {$from..$to}

echo "I am in $(pwd)" # executes pwd and interpolates output
echo "I am in $PWD" interpolates the variable

clear

read name # reads the value

if [["$name" != "$USER" ]]; then
    echo "Your name is not your username"
else
    echo "Your name is your username"
fi

read age

if [["$age" -eq 15]]; then
    echo "Your age is 15"
else
    echo "Your age is not 15"
fi

if [[-z "Name" ]]; then
    echo "Name is unset"
fi

# -ne not equal
# -lt less than
# -gt greater than
# -le less than or equal to
# -ge greater than equal

email=me@gmail.com

if [[ "$email" =~ [a-z]+@[a-z]{2,}\.(com|net|org) ]]; then
    echo "Valid email"
else
    echo "Invalid email"
fi

kill %2 # kill job number 2

alias -p # print all aliases

echo $(( 10 + 5 )) # arithematic context

ls -l | grep "\.txt" # gets all the text files in directory

Contents = $(cat file.txt)

echo -e "START OF FILE\n$Contents\nEND OF FILE"