new standard tasks for coherency
This commit is contained in:
@ -12,6 +12,8 @@ BASHTUTOR_TASK_FILE_LIST+=(tasks/exit_statuses.sh)
|
||||
BASHTUTOR_TASK_FILE_LIST+=(tasks/conditional_execution.sh) # cat learned
|
||||
BASHTUTOR_TASK_FILE_LIST+=(tasks/functions.sh)
|
||||
BASHTUTOR_TASK_FILE_LIST+=(tasks/redirections.sh)
|
||||
BASHTUTOR_TASK_FILE_LIST+=(tasks/pipe.sh) # grep learned
|
||||
BASHTUTOR_TASK_FILE_LIST+=(tasks/command_substition.sh)
|
||||
BASHTUTOR_TASK_FILE_LIST+=(tasks/glob.sh)
|
||||
BASHTUTOR_TASK_FILE_LIST+=(tasks/complex_expension_monk_task.sh)
|
||||
BASHTUTOR_TASK_FILE_LIST+=(tasks/logic.sh)
|
||||
|
28
bash_module/tasks/command_substition.sh
Normal file
28
bash_module/tasks/command_substition.sh
Normal file
@ -0,0 +1,28 @@
|
||||
function description() {
|
||||
echo "tuna" > bowl
|
||||
|
||||
echo "I assume you 'grep'-ed for the option and typed it out into the variable." \
|
||||
"This works, but we are lazy computer people, it would never do."
|
||||
echo -e "Instead imagine that you could store the output of grep directly in the variable." \
|
||||
"This is something ${BOLD}command substitution${NORMAL} is useful for." \
|
||||
"The name is telling, it substitutes itself with the output of a command inplace."
|
||||
echo " $ SOLUTION=\$(man --help | grep cache)"
|
||||
echo ""
|
||||
echo "Well um, now the whole line is stored in SOLUTION," \
|
||||
"but if you were to write a regex to parse that," \
|
||||
"your job security would be ensured, I can guarantee that much."
|
||||
echo ""
|
||||
echo "Anyway, Its time to make it up for our fuzzy friend, the cat."
|
||||
echo ""
|
||||
echo -e "${BLUE}# Store the contents of the file 'bowl' in the variable CAT."
|
||||
}
|
||||
|
||||
function hint() {
|
||||
echo "You should be able to figure this out..."
|
||||
}
|
||||
|
||||
function validate() {
|
||||
if [ "$CAT" == "$(cat bowl)" ]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
41
bash_module/tasks/pipe.sh
Normal file
41
bash_module/tasks/pipe.sh
Normal file
@ -0,0 +1,41 @@
|
||||
function description() {
|
||||
echo -e "Now that you can effortlessly manipulate ${ITALICS}File Descriptors${NORMAL}" \
|
||||
"to direct certain types of output to certain files," \
|
||||
"it's time you learn some more ingenious tricks available through I/O redirection. "
|
||||
echo ""
|
||||
echo "What if you want to connect the output of one application directly" \
|
||||
"to the input of another?" \
|
||||
"That way, you could build a sort of chain to process output."
|
||||
echo ""
|
||||
echo ""
|
||||
echo -e "Let me teach you the command you will use with pipes the most often:" \
|
||||
"${BOLD}G${NORMAL}lobal ${BOLD}Re${NORMAL}gex ${BOLD}P${NORMAL}rint," \
|
||||
"or 'grep' for short."
|
||||
echo "'grep' searches its input based on its first argument and print the lines" \
|
||||
"which contain a match."
|
||||
echo "For example:"
|
||||
echo " $ cat myfile | grep mystring"
|
||||
echo ""
|
||||
echo -e "'cat' outputs our file and the pipe created with the ${YELLOW}|${NORMAL}" \
|
||||
"symbol redirects it to the input of 'grep'."
|
||||
echo ""
|
||||
echo "However, do you remember the animal abuse I mentioned? I just commited it."
|
||||
echo "'grep' is perfectly capable of reading files on its own:"
|
||||
echo " $ grep mystring myfile"
|
||||
echo ""
|
||||
echo "One more important concept: pipes are continuous." \
|
||||
"The process on the left need not to exit before the one on right can start" \
|
||||
"reading its output."
|
||||
echo ""
|
||||
echo -e "${BLUE}# Find out which man option refreshes its cache and store it in \$SOLUTION!${NORMAL}"
|
||||
}
|
||||
|
||||
function hint() {
|
||||
echo "Get the help message of man with its --help option and grep for the keyword 'cache'."
|
||||
}
|
||||
|
||||
function validate() {
|
||||
if [ "$SOLUTION" == "-u" ] || [ "$SOLUTION" == "--update" ]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
Reference in New Issue
Block a user