-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial.sh
More file actions
executable file
·172 lines (146 loc) · 5.67 KB
/
Copy pathtutorial.sh
File metadata and controls
executable file
·172 lines (146 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
#Introduction to BASH
#LILUG April 2025
#This is a comment
#I use 'echo' to say things inside of the script.
#Here I send 3 strings into the echo command, with the middle calling the username by a variable.
#This variable is built into Bash and is discussed more in lesson_e.
echo 'Welcome to the tutorial' $USER'!'
#Here is a 'while' loop. The loop goes from here until 'done'.
#'read' with these options creates a dialog and listens for a yes or no.
#Yes = y or Y, No = n or N.
while true; do
read -r -p "echo 'Are you ready to begin?' [Y/N] " yn
case $yn in
[Yy]* )
echo "Okay, let's go!"
break;;
[Nn]* ) echo 'No problem, we can come back to this later.'
echo 'If you want to view the scripts or files on your own, they can be found here:'
echo $PWD
echo ''
#exit the tutorial completely
exit;;
#If something starting with something other than y or n is entered loop the script and ask politely for something correct.
#Technically yolo and noob are correct entries... I see no problem with this. Remove the * if you do.
* ) echo 'Yes or No?' ;;
esac
done
#While loop ends
echo 'This tutorial presents several text documents along the way.'
echo 'We will see which common programs are available to use.'
#Run a script to detect some common text editors and return to this one
$PWD/scripts/text-editor-check.sh
#Dialog to ask which editor is used
while true; do
read -r -p "echo 'Which program will you like to use to view the documents?' [vim/nano/less/more/showit.sh] " yn
case $yn in
#vim
[Vv]* )
editor=vim
echo $editor
break;;
#nano
[Nn]* )
editor=nano
echo $editor
break;;
#less
[Ll]* )
editor=less
echo $editor
break;;
#more
[Mm]* )
editor=more
echo $editor
break;;
#showit.sh
[Ss]* )
editor=$PWD/scripts/showit.sh
echo $editor
break;;
#Give the user another chance to redeem themselves...
* ) $PWD/scripts/text-editor-check.sh ;;
esac
done
#Leave case dialog and proceed with the program
#'editor' is the text editor the user picked
#'$editor' is how we will call the preferred one for the rest of this tutorial
echo 'The documents will be opened automatically by this program:'
echo $editor
#I can make another yes/no dialog inside this one to let users reconsider.
#If I do this, it will allow users to select another program if they typed wrong.
#However, I will not do that. We are still really early in the script.
#We will strike a balance by making it quicker/easier for the 90% of people who type right.
#The other 10% should not be too annoyed to re-run at this stage.
#Compromise to please the majority when possible.
echo 'If you want to change programs, please exit (Ctrl C) and re-run tutorial.sh again.'
read -p "Press enter to continue"
$PWD/scripts/lesson-list.sh
#For this while loop, I choose to name the case variable for the dialog strt.
#This is not necessary in this case but having unique variables is a good idea in the event code combines together at a later point.
#I picked strt as it is unlikely to be typed anywhere else in this project, and short for "start".
while true; do
read -r -p "echo 'Which lesson should we start with?' [S/A/B/C/D/E/F/G] " strt
case $strt in
[Ss]* )
#Lesson A
$editor $PWD/lessons/lesson_a/welcome.md
#Lesson B
$PWD/lessons/lesson_b/shell-samurai.sh $editor
#Lesson C
$PWD/lessons/lesson_c/build-a-script.sh $editor
#Lesson D
$PWD/lessons/lesson_d/combine-commands.sh $editor
#Lesson E
$PWD/lessons/lesson_e/variables.sh $editor
#Lesson F
$PWD/lessons/lesson_f/introducing-arguments.sh $editor
#Lesson G
$PWD/lessons/lesson_g/implementing-exit-codes.sh $editor
break;;
[Aa]* )
#Lesson A
$editor $PWD/lessons/lesson_a/welcome.md
break;;
[Bb]* )
#Lesson B
$PWD/lessons/lesson_b/shell-samurai.sh $editor
break;;
[Cc]* )
#Lesson C
$PWD/lessons/lesson_c/build-a-script.sh $editor
break;;
[Dd]* )
#Lesson D
$PWD/lessons/lesson_d/combine-commands.sh $editor
break;;
[Ee]* )
#Lesson E
$PWD/lessons/lesson_e/variables.sh $editor
break;;
[Ff]* )
#Lesson F
$PWD/lessons/lesson_f/introducing-arguments.sh $editor
break;;
[Gg]* )
#Lesson G
$PWD/lessons/lesson_g/implementing-exit-codes.sh $editor
break;;
* ) $PWD/scripts/lesson-list.sh ;;
esac
done
#This ends the tutorial script and exits
echo "I hope you have enjoyed this tutorial."
echo ''
echo "I enjoyed making it,"
echo "and hope you learned as much as I did with this script."
echo "Check my Github profile for more projects:"
echo ''
echo "https://github.com/Trimble-tech"
echo ''
echo "Additionally, check out the Long Island Linux User Group:"
echo "https://lilug.org/"
sleep 5
exit