Shell Script to display current date, calendar, and the number of user logged
Posted in Academic
This script use the concept of command substitution. It allows allows the output of a command to replace the command name. There are two forms:
$(command)
or
`command`
Bash shell performs the expansion by executing command and replacing the command substitution with the standard output of the command, with any trailing newlines deleted. Embedded newlines are not deleted, but they may be removed during word splitting.
For example you can execute date command to display todays date and then set a variable called NOW:
NOW=$(date)
or
NOW=`date`
To display back variable value simply run echo command:
echo $NOW
Sample Shell Script
#!/bin/bash # Shell script to display current date, calendar, and the number of # user logged. # ------------------------------------------------------------------------- # Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/> # This script is licensed under GNU GPL version 2.0 or above # ------------------------------------------------------------------------- # This script is part of nixCraft shell script collection (NSSC) # Visit http://bash.cyberciti.biz/ for more information. # ---------------------------------------------------------------------- echo "Today is $(date)" echo "" echo "Calendar :" cal echo "Number of users currently logged : $(who | wc -l)"
Download - Email this to a friend - Printable version
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: bash shell script, command substitution, current date, date command, echo command, grave accents, newlines, shell pipes, variable value, wc command ~ Last updated on: April 3, 2008

