#!/bin/bash

# Script for demonstrating echo output coloring, if statement, and test command

# clear the terminal window
clear

# demo echo color coding

echo "Greetings, $USER"
echo ""
echo -e "and \e[1;32m\e[41mHappy Holidays\e[0m too!"
echo ""
echo -e "I hope you had a \e[5mspooky\e[0m \e[0;33mHalloween\e[0m!"
echo ""

# demo the if statement and test command

echo "Testing for the existance of file textfile1.txt..."
echo ""

if test -e textfile1.txt; then
   echo "The file textfile1.txt exists."
   echo ""
else
   echo -e "\e[0;31mThe file textfile1.txt doesn't exist.\e[0m"
   echo ""
fi

echo "Now, testing to see if the text files in the current directory contain the word demo..."
echo ""

if grep -q demo *.txt 2> /dev/null; then
   echo "There are text files in the current directory ($PWD) that contain the word \"demo\""
else
   echo "Sorry, there are no text files in the current directory ($PWD) that contain the word \"demo\""
fi

echo ""
echo "Testing to see if you can modify /var/log/messages..."
echo ""

SUCCESS="\e[0;32m"
ERROR="\e[0;31m"
NORMAL="\e[0m"

if [ -w /var/log/messages ]; then
   echo -e "$SUCCESS Congratulations, you have write privileges to /var/log/messages.$NORMAL"
else
   echo -e "$ERROR Sorry, you don't have write privileges to /var/log/messages.$NORMAL"
fi

echo ""
