helloWorld In Bash

Background

Had a Hard and Productive Heavy lifting with database work this weekend.

To lighten up the mood a bit, let us play around with Linux.

 

Hello World in Bash

Outline

  1. Environment Variable
    • USER
      • Get Username by accessing the global variable $USER
      • Place it in the envUsername variable
  2. System Variables
    • Get Date $(date)
      • Get Date Hours by accessing $(date +%H)
  3. Depending on the hours get timeofDay
  4. Display Salutation

 

Code


#!/bin/bash

envUsername=""
iDateHours=0
timeofDay=""

#######################################
# Get Environment variable
#######################################
envUsername=$USER

#######################################
# Date
#######################################
iDateHours=$(date +%H)

#echo "Date ( Hours):- $iDateHours"

##########################################
# Get Time of Day
##########################################
if [ "$iDateHours" -lt 12 ]; then

    timeofDay="morning"

elif [ "$iDateHours" -eq 12 ]; then

    timeofDay="noon"

elif [ "$iDateHours" -lt 17 ]; then

    timeofDay="afternoon"

elif [ "$iDateHours" -lt 21 ]; then

    timeofDay="evening"

else

    timeofDay="night"

fi

############################################
# Display username if available
############################################
if [ "$envUsername" = "" ]; then

   echo "Good $timeofDay"

else

   echo "$envUsername, Good $timeofDay"

fi

Output

 

Source Code Control

GitLab

HelloWorld In Languages

helloWorld.sh

Link

One thought on “helloWorld In Bash

Leave a Reply to Linux:- Login Scripts – Day 01 | Learning in the Open Cancel reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s