From 6f7f1c31c9e50712276a1b73f647ad59320584a3 Mon Sep 17 00:00:00 2001 From: Llewellyn van der Merwe Date: Sat, 3 Oct 2020 11:07:23 +0200 Subject: [PATCH] Week 5: Assignment - greetme --- week-05/greetme | 50 ++++++++++++++++++++++++++ week-05/greetme.log | 13 +++++++ week-05/greetme_builder | 58 ++++++++++++++++++++++++++++++ week-05/greetme_builder.log | 70 +++++++++++++++++++++++++++++++++++++ week-05/greetme_output | 7 ++++ 5 files changed, 198 insertions(+) create mode 100755 week-05/greetme create mode 100644 week-05/greetme.log create mode 100755 week-05/greetme_builder create mode 100644 week-05/greetme_builder.log create mode 100644 week-05/greetme_output diff --git a/week-05/greetme b/week-05/greetme new file mode 100755 index 0000000..974f66f --- /dev/null +++ b/week-05/greetme @@ -0,0 +1,50 @@ +#!/bin/bash +#/------------------------------------------------------------------------------------------------------- +# +# @version 1.0.0 +# @build 2nd Oct, 2020 +# @package SDEV-415-81: Linux/ Unix Programming I - Fall 2020 (2020FA) +# @sub-package Week 5: Assignment - greetme +# @author Llewellyn van der Merwe +# @copyright Copyright (C) 2020. All Rights Reserved +# @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html +# +#/-------------------------------------------------------------------------------------------------------- + + +# 1. Write a bash script called greetme that will do the following: +# a. Contain a comment section with your name, the name of this script, and the purpose of this script. +# b. Greet the user (using the correct environment variable) +echo "Hi, $USER" + +# c. Print the date and the time +datetime=$(date '+%d/%m/%Y %H:%M:%S'); +echo "$datetime" + +# d. Print the value of the TERM, PATH, and HOME variables +echo "$TERM" +echo "$PATH" +echo "$HOME" + +# e. Print Please, could you loan me $50.00? +echo 'Please, could you loan me $50.00?' + +# f. Tell the user Good-bye +echo "Good-bye, $USER" + +# Make sure your script is executable. (chmod +x greetme) +chmod +x greetme + + +# 2. Answer the following question: +# What was the first line of your script? Why do you need this line? + +# The first line was #!/bin/bash + +# This #! is called the "hash-bang", "she-bang" or "sha-bang" +# and the /bin/bash is the standard location/path to the Bourn shell + +# When the file is run as an executable, this line tells the interactive shell +# what kind of interpreter to run for this file, and where it can be found, +# but should you run the file as "bash greetme.sh", the first line is ignored. + diff --git a/week-05/greetme.log b/week-05/greetme.log new file mode 100644 index 0000000..337f2f5 --- /dev/null +++ b/week-05/greetme.log @@ -0,0 +1,13 @@ +Script started on 2020-10-02 03:53:07+02:00 [TERM="xterm-256color" TTY="/dev/pts/0" COLUMNS="105" LINES="49"] +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ exit./greetme +Hi, llewellyn +02/10/2020 03:53:10 +xterm-256color +/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin +/home/llewellyn +Please, could you loan me $50.00? +Good-bye, llewellyn +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ exit +exit + +Script done on 2020-10-02 03:53:16+02:00 [COMMAND_EXIT_CODE="0"] diff --git a/week-05/greetme_builder b/week-05/greetme_builder new file mode 100755 index 0000000..8d8cdf7 --- /dev/null +++ b/week-05/greetme_builder @@ -0,0 +1,58 @@ +#!/bin/bash +# THE FILE BUILDER +echo '#!/bin/bash' > greetme +echo '#/------------------------------------------------------------------------------------------------------- +# +# @version 1.0.0 +# @build 2nd Oct, 2020 +# @package SDEV-415-81: Linux/ Unix Programming I - Fall 2020 (2020FA) +# @sub-package Week 5: Assignment - greetme +# @author Llewellyn van der Merwe +# @copyright Copyright (C) 2020. All Rights Reserved +# @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html +# +#/--------------------------------------------------------------------------------------------------------' >> greetme +echo ' + +# 1. Write a bash script called greetme that will do the following: +# a. Contain a comment section with your name, the name of this script, and the purpose of this script. +# b. Greet the user (using the correct environment variable) +echo "Hi, $USER" + +# c. Print the date and the time' >> greetme +echo -n "datetime=" >> greetme +echo -n '$' >> greetme +echo "(date '+%d/%m/%Y %H:%M:%S');" >> greetme +echo 'echo "$datetime" + +# d. Print the value of the TERM, PATH, and HOME variables +echo "$TERM" +echo "$PATH" +echo "$HOME" + +# e. Print Please, could you loan me $50.00?' >> greetme +echo -n "echo 'Please, could you loan me " >> greetme +echo -n '$' >> greetme +echo -n "50.00?'" >> greetme +echo ' + +# f. Tell the user Good-bye +echo "Good-bye, $USER" + +# Make sure your script is executable. (chmod +x greetme) +chmod +x greetme +' >> greetme +echo ' +# 2. Answer the following question: +# What was the first line of your script? Why do you need this line? ' >> greetme +echo ' +# The first line was #!/bin/bash + +# This #! is called the "hash-bang", "she-bang" or "sha-bang" +# and the /bin/bash is the standard location/path to the Bourn shell + +# When the file is run as an executable, this line tells the interactive shell +# what kind of interpreter to run for this file, and where it can be found, +# but should you run the file as "bash greetme.sh", the first line is ignored. +' >> greetme + diff --git a/week-05/greetme_builder.log b/week-05/greetme_builder.log new file mode 100644 index 0000000..1ff12cb --- /dev/null +++ b/week-05/greetme_builder.log @@ -0,0 +1,70 @@ +Script started on 2020-10-02 03:57:35+02:00 [TERM="xterm-256color" TTY="/dev/pts/0" COLUMNS="105" LINES="49"] +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ echo '#!/bin/bash' > greetme +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ echo '#/------------------------------------------------------------------------------------------------------- +> # +> # @version1.0.0 +> # @build2nd Oct, 2020 +> # @packageSDEV-415-81: Linux/ Unix Programming I - Fall 2020 (2020FA) +> # @sub-packageWeek 5: Assignment - greetme +> # @authorLlewellyn van der Merwe +> # @copyrightCopyright (C) 2020. All Rights Reserved +> # @licenseGNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html +> # +> #/--------------------------------------------------------------------------------------------------------' >> greetme +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ echo ' +> +> # 1. Write a bash script called greetme that will do the following: +> # a. Contain a comment section with your name, the name of this script, and the purpose of this script. +> # b. Greet the user (using the correct environment variable) +> echo "Hi, $USER" +> +> # c. Print the date and the time' >> greetme +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ echo -n "datetime=" >> greetme +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ echo -n '$' >> greetme +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ echo "(date '+%d/%m/%Y %H:%M:%S');" >> greetme +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ echo 'echo "$datetime" +> +> # d. Print the value of the TERM, PATH, and HOME variables +> echo "$TERM" +> echo "$PATH" +> echo "$HOME" +> +> # e. Print Please, could you loan me $50.00?' >> greetme +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ echo -n "echo 'Please, could you loan me " >> greetme +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ echo -n '$' >> greetme +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ echo -n "50.00?'" >> greetme +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ echo ' +> +> # f. Tell the user Good-bye +> echo "Good-bye, $USER" +> +> # Make sure your script is executable. (chmod +x greetme) +> chmod +x greetme +> ' >> greetme +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ echo ' +> # 2. Answer the following question: +> # What was the first line of your script? Why do you need this line? ' >> greetme +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ echo ' +> # The first line was #!/bin/bash +> +> # This #! is called the "hash-bang", "she-bang" or "sha-bang" +> # and the /bin/bash is the standard location/path to the Bourn shell +> +> # When the file is run as an executable, this line tells the interactive shell +> # what kind of interpreter to run for this file, and where it can be found, +> # but should you run the file as "bash greetme.sh", the first line is ignored. +> ' >> greetme +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ chmod +x greetme +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ ./greetme +Hi, llewellyn +02/10/2020 03:59:12 +xterm-256color +/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin +/home/llewellyn +Please, could you loan me $50.00? +Good-bye, llewellyn +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ ./greetme > greetme_output +]0;llewellyn@micron: ~/Linux Programming I/1_Week5_1llewellyn@micron:~/Linux Programming I/1_Week5_1$ exit +exit + +Script done on 2020-10-02 03:59:34+02:00 [COMMAND_EXIT_CODE="0"] diff --git a/week-05/greetme_output b/week-05/greetme_output new file mode 100644 index 0000000..d4fa534 --- /dev/null +++ b/week-05/greetme_output @@ -0,0 +1,7 @@ +Hi, llewellyn +02/10/2020 03:59:28 +xterm-256color +/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin +/home/llewellyn +Please, could you loan me $50.00? +Good-bye, llewellyn