| 1 | #!/bin/sh
|
| 2 | BLUE="\033[34m"
|
| 3 | RED="\033[31m"
|
| 4 | GREEN="\033[32m"
|
| 5 | RESET="\033[0m"
|
| 6 |
|
| 7 | pause() {
|
| 8 | printf "$1"
|
| 9 | read user_input
|
| 10 | echo ""
|
| 11 | }
|
| 12 |
|
| 13 | pause "Welcome to Shelllings [press ENTER]"
|
| 14 |
|
| 15 | echo "This program is meant to help you understand most posix shells,"
|
| 16 | echo "like bash or zsh. You already ran the command 'sh run_shell.sh'"
|
| 17 | echo "but the command 'sh' doesn't really exist on most systems."
|
| 18 | echo "Run 'ls -l /bin/sh' to see if there is a link to another program."
|
| 19 | pause "Let's test it out [press ENTER for ls -l /bin/sh]"
|
| 20 |
|
| 21 | printf "${BLUE}$(ls -l /bin/sh)${RESET}"
|
| 22 | echo ""
|
| 23 |
|
| 24 | USER_SHELL=$(ls -l /bin/sh | awk '{print $NF}')
|
| 25 |
|
| 26 | echo ""
|
| 27 | if [ "$USER_SHELL" = "sh" ]; then
|
| 28 | echo "Looks like you are actually using sh, not everyone has it"
|
| 29 | printf "like this. Many shells are changed. "
|
| 30 | else
|
| 31 | echo "From the command above, we can see that you are actually"
|
| 32 | printf "running ${BLUE}$USER_SHELL${RESET} under the hood. "
|
| 33 | fi
|
| 34 |
|
| 35 | echo "Bash is switched to a "
|
| 36 | echo "POSIX-compatible mode, dash also only implements POSIX features."
|
| 37 | echo "There are many different shells but we will be sticking with"
|
| 38 | echo "POSIX compliant programs and commands. Meaning just about"
|
| 39 | echo "every shell you use will be able to understand and run these"
|
| 40 | echo "commands. This will not always be the case, however."
|
| 41 | pause "[press ENTER]"
|
| 42 |
|
| 43 | printf "The LICENSE file is going to be used often later, ${RED}don't\n"
|
| 44 | printf "remove the LICENSE file${RESET}. Thanks."
|
| 45 | pause ""
|
| 46 |
|
| 47 | echo "To use the program shelllings, let's run the command"
|
| 48 | echo "'sh shelllings.sh test' to see if it's able to be run"
|
| 49 | pause "[sh shelllings.sh test]"
|
| 50 |
|
| 51 | if sh shelllings.sh test; then
|
| 52 | printf "${GREEN}Passed${RESET}"
|
| 53 | echo ""
|
| 54 | else
|
| 55 | printf "${RED}ERROR failed${RESET}"
|
| 56 | echo ""
|
| 57 | exit 1
|
| 58 | fi
|
| 59 |
|
| 60 | echo ""
|
| 61 | echo "No error message meant that it has not failed. Lets continue on"
|
| 62 | pause "and see what exercises there are right now [ls exercises]"
|
| 63 |
|
| 64 | all_ex=$(ls exercises)
|
| 65 | printf "${BLUE}$all_ex${RESET}"
|
| 66 | echo ""
|
| 67 |
|
| 68 | echo ""
|
| 69 | pause "[press ENTER]"
|
| 70 |
|
| 71 | amount=$(ls exercises | wc -l)
|
| 72 |
|
| 73 | echo "Looks like there are $amount exercises. You should know that"
|
| 74 | echo "you can skip through the ones you already know or come back to"
|
| 75 | echo "ones you already did. You can run 'sh shelllings.sh n' where n"
|
| 76 | echo "is the numbered exercise. You don't need to type the 0's in"
|
| 77 | echo "front. Let's get started with the first exercise"
|
| 78 | pause "[sh shelllings.sh 1]"
|
| 79 |
|
| 80 | sh shelllings.sh 1 || {
|
| 81 | echo "Looks like it failed. Go on over to the exercises/ folder and"
|
| 82 | printf "fix it then run ${GREEN}sh shelllings 1${RESET} again.\n"
|
| 83 | }
|