Surprise! We've been running on hardware provided by BuyVM for a few months and wanted to show them a little appreciation.
Running a paste site comes with unique challenges, ones that aren't always obvious and hard to control. As such, BuyVM offered us a home where we could worry less about the hosting side of things and focus on maintaining a clean and useful service! Go check them out and show them some love!
Submitted on July 21, 2015 at 02:43 AM

Section 1 (Bash)

#! /usr/bin/env bash
# 
# Add name, id and other relevant info up here
#

# Declare a variable A as an integer

# Check to see if anything is passed to script and store passed value in variable A 

# If nothing is passed to script then store random number (range 1-15) to variable A

# $# shows how many command line arguments are there if it is zero there are no command line arguments. 
if [ $# -eq 0 ]
then
  A=$((RANDOM%15+1))
else
  A=$1
fi

# If variable A contains the value 0 then replace it with a random number (range 1-20)
if [ "$A" -eq 0 ]
then
  A=$((RANDOM%20+1))
fi

# Function ADD: If value is within range 1-5 add two to that number four times
ADD() {
  if [ "$A" -gt 1 -a "$A" -lt 5 ] 
  then 
    ans=$((A+A+A))
    echo $ans
  fi
}

# Function CUBE: If value is within range 6-10 find the cube of that number
CUBE() {
  if [ "$A" -gt 6 -a "$A" -lt 10 ] 
  then
    ans=$((A*A*A))
    echo $ans
  fi
}

# Function FACT: If 11 or more find the factorial and divide result by a random number
FACT() {
  if [ $A -lt 11 ]
  then
    if [ $A -lt 2 ] 
    then 
      $ans=1
    else 
      N=$(( $( FACT $((A - 1)) ) * $A ))
      ans= $((N/RANDOM))
      echo $ans
    fi
  fi
}

PS3='Please enter an option: '
options=( "Option 1" "Option 2" "Option 3" "Quit" ) # an array
select opt in "${options[@]}" # the @ refers to a sequence of values or an array. So basically it is saying for all the items in the array options...
do
  case $opt in
    "Option 1")
      ADD $A
      ;;
    "Option 2")
      CUBE $A
      ;;
    "Option 3")
      FACT $A
      ;;
    "Quit")
      break
      ;;
    *) echo "Invalid option";;
  esac
done



# use shellcheck.net to check for errors in the script.
#NOTES:
# $((EXPR)) - Arithmetic expansion used to make calculations in bash.