Write three bash shell scripts that say “Hello”. The first script should be name
ID: 3820650 • 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.
$ 04-hello-1 #correct input
Hello! Today is Sun Apr 09 14:42:59 MDT 2017
$ 04-hello-2 Sally #correct input (no error checking)
Hello, Sally! Today is 09 Apr 2017.
$ 04-hello-3 #incorrect input (no name) with error checking
USAGE: 04-hello-3 Where is the name of the person running the script. Ex: hello-3 Sally
$ 04-hello-3 Sally #correct input
Hello, Sally! Today is 09 Apr, of 2017.
Explanation / Answer
Note:-Run above program as chmod +x file_name
with the help of this command file is executable
after that ./file_patah arg1(if you want to give )
-----------------------------------------------
04-hello-1
#!/bin/bash
echo -n "Hello! Today is "
date
--------------------------------------------------------------------------------------------
04-hello-2
#!/bin/bash
echo -n "Hello,$1 Today is "
now="$(date)"
now="$(date +'%d %b %Y')"
echo "$now"
------------------------------------------------------------------
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.