Shell Script To Display Last Five Lines Of The File

in Categories Academic last updated April 12, 2008

Given the filename by the user as the input, write a shell script to display the last five lines of the file.

Shell Script

Command Line Argument

You can read file name as command line argument:

Shell Script accept password using read commnad

in Categories Script last updated April 10, 2008

Shell script to create list of backup files in ~/.mybackup file. Use with mybackup shell script

in Categories Backup last updated April 9, 2008

Shell Script to read price of an article and calculate discount

in Categories Shell Math last updated April 4, 2008

Script to display sum of two number and to do calculations such as +, -, / etc

in Categories Shell Math last updated April 15, 2008

Shell Script to display current date, calendar, and the number of user logged

in Categories Academic last updated April 3, 2008

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

Shell Script to ask user his / her name and then display it with a G’Day/Good morning message

in Categories Academic last updated April 3, 2008

This script greets user with a message. Then it displays prompt asking user her name. Once name entered it will display Gooday message using echo command.

read statement will read one line from the user (keyboard) or from file and store it to a variable called yourname.

Script to Store given command and execute them

in Categories Academic last updated April 3, 2008

Write script to store the following command and execute them:
a) date
b) echo “Message”
c) cal

Shell Script To Display The Text Entered By The User in Bold

in Categories Academic last updated April 15, 2008

Write a shell script to display the text entered by the user in bold?

You need to use the tput utility to display text in bold. It uses the terminfo database to make the values of terminal-dependent capabilities and information available to the shell, to initialize or reset the terminal, or return the long name of the requested terminal type. tput bold turns on bold (extra bright) mode.