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
- Environment Variable
- USER
- Get Username by accessing the global variable $USER
- Place it in the envUsername variable
- USER
- System Variables
- Get Date $(date)
- Get Date Hours by accessing $(date +%H)
- Get Date $(date)
- Depending on the hours get timeofDay
- 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
[…] hello world in bash Link […]