Write three bash shell scripts that say “Hello”. The first script should be name
ID: 3575432 • Letter: W
Question
Write three bash shell scripts that say “Hello”. The first script should be named 04-
hello-1, the second, 04-hello-2, and the third, 04-hello-3. All three will also tell the current
date. See the example runs below for clarification on how these scripts should work. (Note
that the $ is the Linux prompt, not part of the command you type.)
i. Hello-1 should simply say “hello” when it runs, and list the current date. The date can be
in any format. It does nothing with command-line parameters.
ii. Hello-2 should say “hello” to the name specified in a single command-line parameter, but
does not need to do any command-line error-checking. It should display only the month,
day of the month, and the year, for the date (not anything else), in the format illustrated
below.
iii. Hello-3 should work just like Hello-2 does, except that there should be a comma between
the day of the month, and the year, and it should check to make sure that a single
command-line parameter is used, and, if not, an appropriate error/help-message is
displayed.
Explanation / Answer
04-hello-1
====================
#!bin/sh
echo "hello"
date
====================
=====================
04-hello-2
=====================
#!bin/sh
echo "hello $1"
DATE=`date +%m-%d-%Y`
echo $DATE
=========================
=========================
04-hello-3
==========================
#!bin/sh
if [ $# -eq 1 ]
then
echo "hello $1"
DATE=`date +%m,%d,%Y`
echo $DATE
else
echo "invalid argument please pass only one argument "
fi
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.