bash module WIP
This commit is contained in:
21
bash_module/arguments_1.sh
Normal file
21
bash_module/arguments_1.sh
Normal file
@ -0,0 +1,21 @@
|
||||
function description() {
|
||||
echo -e "As you might have noticed Bash has complained about what you have just entered." \
|
||||
"This is because it ${ITALICS}tried${NORMAL} to run what you just entered as" \
|
||||
"a program, but failed finding it."
|
||||
echo ""
|
||||
echo -e "Now, let me introduce you to your first valid program: ${BOLD}echo${NORMAL}." \
|
||||
"echo's purpose is to print to ${ITALICS}stdout${NORMAL} (more on that later)." \
|
||||
"This very line you are reading uses echo."
|
||||
echo ""
|
||||
echo -e "${BLUE}# Try echoing some arbitrary message.${NORMAL}"
|
||||
}
|
||||
|
||||
function hint() {
|
||||
echo "For example, 'echo Hello World'"
|
||||
}
|
||||
|
||||
function validate() {
|
||||
if [ "$1" == "echo" ]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
41
bash_module/arguments_2.sh
Normal file
41
bash_module/arguments_2.sh
Normal file
@ -0,0 +1,41 @@
|
||||
function description() {
|
||||
echo "Nice!"
|
||||
echo ""
|
||||
echo "Now, we can gain an understanding how word splitting works."
|
||||
echo ""
|
||||
echo "Bash does not perform word splitting at every whitespace character," \
|
||||
"rather every amount of whitespace will result in one split."
|
||||
echo "For example:"
|
||||
echo " $ echo Hello World"
|
||||
echo " Hello World"
|
||||
echo ""
|
||||
echo -e "The extra spaces make no difference." \
|
||||
"If we ${BOLD}want${NORMAL} the extra whitespace," \
|
||||
"we need to pass the sentence as one single argument." \
|
||||
"We can do this by using quotes:"
|
||||
echo " $ echo \"This is a test.\""
|
||||
echo " This is a test."
|
||||
echo ""
|
||||
echo -e "Quotes group everything inside them into a single argument." \
|
||||
"The argument is: '${ITALICS}This is a test.${NORMAL}'" \
|
||||
"... specifically spaced." \
|
||||
"Note that the quotes are not part of the argument" \
|
||||
"- Bash removes them before handing the argument to echo." \
|
||||
"echo prints this single argument out just like it always does."
|
||||
echo ""
|
||||
echo "touch is another common program" \
|
||||
"used for creating empty files or updating their" \
|
||||
"file access dates."
|
||||
echo ""
|
||||
echo -e "${BLUE}# Commit a war crime by creating a file with a space in its name.${NORMAL}"
|
||||
}
|
||||
|
||||
function hint() {
|
||||
echo "$ touch \"space space space those are 3 spaces\""
|
||||
}
|
||||
|
||||
function validate() {
|
||||
if [ -n "$(find -iname '* *')" ]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
35
bash_module/arguments_3.sh
Normal file
35
bash_module/arguments_3.sh
Normal file
@ -0,0 +1,35 @@
|
||||
function description() {
|
||||
echo "Congrats to becoming an Honorary Serbian!"
|
||||
echo ""
|
||||
echo "As it was said before the program and its arguments are always separated by" \
|
||||
"whitespace."
|
||||
echo "This is important to remember. For example, the following is wrong:"
|
||||
echo " $ [0 == 0]"
|
||||
echo "bash: [0: command not found"
|
||||
echo "This is intended to test whether two values are equal." \
|
||||
"It's reasonable to assume that whitespace around '[' and ']' doesn't matter," \
|
||||
"but '[' is actually a program, and it requires its last argument to be ']'." \
|
||||
"(We will cover the '[' program in more detail later.)" \
|
||||
"Therefore, we must separate '[' and ']' from 0s," \
|
||||
"otherwise Bash will think we are trying to execute" \
|
||||
"a command named [0 with the arguments == and 0]."
|
||||
echo ""
|
||||
echo "The correct command separates all arguments with whitespace."
|
||||
echo ""
|
||||
echo "(We see a lot of people who are confused by this behavior;" \
|
||||
"they think that they can omit the whitespace between it and its arguments," \
|
||||
"so we need to present this particular example early.)"
|
||||
echo ""
|
||||
echo -e "${BLUE}# Fix our malformed command so that it checks" \
|
||||
"that 0 is in fact equal to 0.${NORMAL}"
|
||||
}
|
||||
|
||||
function hint() {
|
||||
echo " $ [ 0 == 0 ]"
|
||||
}
|
||||
|
||||
function validate() {
|
||||
if [ "$*" == "[ 0 == 0 ]" ]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
47
bash_module/command.sh
Normal file
47
bash_module/command.sh
Normal file
@ -0,0 +1,47 @@
|
||||
function description() {
|
||||
echo -e "BASH is an acronym for" \
|
||||
"${BOLD}B${NORMAL}ourne ${BOLD}A${NORMAL}gain ${BOLD}Sh${NORMAL}ell." \
|
||||
"It is based on the Bourne shell and is mostly compatible with its features. "
|
||||
echo ""
|
||||
echo "A shell is a language interpreter which interacts with a human user." \
|
||||
"This is accomplished by repeatedly taking and executing commands." \
|
||||
"The term shell is most often associated capabilities to communicate with the" \
|
||||
"operating system."
|
||||
echo ""
|
||||
echo "We will start start by getting you up speed with how to issue a command." \
|
||||
"For this you will have to know how a command looks like:"
|
||||
echo ""
|
||||
echo " $ program-name argument-1 argument-2 argument-N"
|
||||
echo ""
|
||||
echo "Many things in Bash have to be separated with white spaces," \
|
||||
"such as the program name and its arguments."
|
||||
echo ""
|
||||
echo "Traditionally, a shell prompt either ends with $, % or #." \
|
||||
"If it ends with $, this indicates a shell that's compatible with the Bourne shell" \
|
||||
"(such as a POSIX shell, or a Korn shell, or Bash)." \
|
||||
"If it ends with %, this indicates a C shell (csh or tcsh);" \
|
||||
"this guide does not cover C shell. If it ends with #," \
|
||||
"this indicates that the shell is running as the system's superuser account (root)," \
|
||||
"and that you should be extra careful." \
|
||||
"In this guide and in most guides in general '$ ' denotes the entire prompt."
|
||||
echo ""
|
||||
echo "Note that the Bash documentation defines commands as such:"
|
||||
echo -e " ${ITALICS}A simple shell command such as 'echo a b c' consists of the command" \
|
||||
"itself followed by arguments, separated by spaces.${NORMAL}"
|
||||
echo "Which is fair, but for clarity's sake we will be referring to the first" \
|
||||
"portion as a 'program'."
|
||||
echo ""
|
||||
echo -e "${BLUE}# To continue, enter what part of the command is 'a'" \
|
||||
"in the following command:${NORMAL}"
|
||||
echo " $ touch a"
|
||||
}
|
||||
|
||||
function hint() {
|
||||
echo "It's an argument."
|
||||
}
|
||||
|
||||
function validate() {
|
||||
if [[ "$1" =~ argument.* ]]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
17
bash_module/greeting.sh
Normal file
17
bash_module/greeting.sh
Normal file
@ -0,0 +1,17 @@
|
||||
function description() {
|
||||
# NOTE: i should add something describing this quide,
|
||||
# said description will be highly dependant on
|
||||
# how closely i will follow
|
||||
# https://mywiki.wooledge.org/BashGuide
|
||||
echo "<placeholder>"
|
||||
echo ""
|
||||
echo -e "${BLUE}# Enter any (e.g. empty) command to continue.${NORMAL}"
|
||||
}
|
||||
|
||||
function hint() {
|
||||
true
|
||||
}
|
||||
|
||||
function validate() {
|
||||
return 1
|
||||
}
|
10
bash_module/task_list.sh
Normal file
10
bash_module/task_list.sh
Normal file
@ -0,0 +1,10 @@
|
||||
BASHTUTOR_TASK_FILE_LIST+=(greeting.sh)
|
||||
BASHTUTOR_TASK_FILE_LIST+=(command.sh)
|
||||
BASHTUTOR_TASK_FILE_LIST+=(arguments_1.sh)
|
||||
BASHTUTOR_TASK_FILE_LIST+=(arguments_2.sh)
|
||||
BASHTUTOR_TASK_FILE_LIST+=(arguments_3.sh)
|
||||
|
||||
BOLD="\033[1m"
|
||||
ITALICS="\033[3m"
|
||||
NORMAL="\033[0m"
|
||||
BLUE="\033[34m"
|
Reference in New Issue
Block a user