From 4e3d7e3e4c3819f9546cd31615df41c9be0ddf62 Mon Sep 17 00:00:00 2001 From: samirm00 Date: Fri, 15 Mar 2024 01:39:55 +0100 Subject: [PATCH] add 01-debug-your-script --- 01-debug-your-script/0-examples/00.md | 24 +++++ 01-debug-your-script/0-examples/01.md | 59 +++++++++++++ 01-debug-your-script/0-examples/01.sh | 40 +++++++++ 01-debug-your-script/0-examples/02.md | 56 ++++++++++++ 01-debug-your-script/0-examples/02.sh | 38 ++++++++ 01-debug-your-script/0-examples/03.sh | 22 +++++ 01-debug-your-script/0-examples/04.sh | 25 ++++++ 01-debug-your-script/0-examples/05.sh | 29 ++++++ 01-debug-your-script/1-blanks/01.sh | 42 +++++++++ 01-debug-your-script/1-blanks/02.sh | 38 ++++++++ 01-debug-your-script/1-blanks/03.sh | 22 +++++ 01-debug-your-script/1-blanks/04.sh | 25 ++++++ 01-debug-your-script/1-blanks/05.sh | 29 ++++++ 01-debug-your-script/1.sh | 107 ----------------------- 01-debug-your-script/2-bugs/01.sh | 40 +++++++++ 01-debug-your-script/2-bugs/02.sh | 38 ++++++++ 01-debug-your-script/2-bugs/03.sh | 22 +++++ 01-debug-your-script/2-bugs/04.sh | 25 ++++++ 01-debug-your-script/2-bugs/05.sh | 29 ++++++ 01-debug-your-script/3-refactor/01.sh | 40 +++++++++ 01-debug-your-script/3-refactor/02.sh | 38 ++++++++ 01-debug-your-script/3-refactor/03.sh | 22 +++++ 01-debug-your-script/3-refactor/04.sh | 25 ++++++ 01-debug-your-script/3-refactor/05.sh | 29 ++++++ 01-debug-your-script/4-modify/01.sh | 42 +++++++++ 01-debug-your-script/4-modify/02.sh | 42 +++++++++ 01-debug-your-script/4-modify/03.sh | 22 +++++ 01-debug-your-script/4-modify/04.sh | 25 ++++++ 01-debug-your-script/4-modify/05.sh | 29 ++++++ 01-debug-your-script/5-chunks/01.sh | 36 ++++++++ 01-debug-your-script/5-chunks/02.sh | 36 ++++++++ 01-debug-your-script/5-chunks/03.sh | 20 +++++ 01-debug-your-script/5-chunks/04.sh | 21 +++++ 01-debug-your-script/5-chunks/05.sh | 25 ++++++ 01-debug-your-script/6-blank-pages/01.sh | 13 +++ 01-debug-your-script/6-blank-pages/02.sh | 13 +++ 01-debug-your-script/6-blank-pages/03.sh | 13 +++ 01-debug-your-script/6-blank-pages/04.sh | 13 +++ 01-debug-your-script/6-blank-pages/05.sh | 13 +++ 39 files changed, 1120 insertions(+), 107 deletions(-) create mode 100644 01-debug-your-script/0-examples/00.md create mode 100644 01-debug-your-script/0-examples/01.md create mode 100755 01-debug-your-script/0-examples/01.sh create mode 100755 01-debug-your-script/0-examples/02.md create mode 100755 01-debug-your-script/0-examples/02.sh create mode 100755 01-debug-your-script/0-examples/03.sh create mode 100755 01-debug-your-script/0-examples/04.sh create mode 100755 01-debug-your-script/0-examples/05.sh create mode 100755 01-debug-your-script/1-blanks/01.sh create mode 100755 01-debug-your-script/1-blanks/02.sh create mode 100755 01-debug-your-script/1-blanks/03.sh create mode 100755 01-debug-your-script/1-blanks/04.sh create mode 100755 01-debug-your-script/1-blanks/05.sh delete mode 100644 01-debug-your-script/1.sh create mode 100755 01-debug-your-script/2-bugs/01.sh create mode 100755 01-debug-your-script/2-bugs/02.sh create mode 100755 01-debug-your-script/2-bugs/03.sh create mode 100755 01-debug-your-script/2-bugs/04.sh create mode 100755 01-debug-your-script/2-bugs/05.sh create mode 100755 01-debug-your-script/3-refactor/01.sh create mode 100755 01-debug-your-script/3-refactor/02.sh create mode 100755 01-debug-your-script/3-refactor/03.sh create mode 100755 01-debug-your-script/3-refactor/04.sh create mode 100755 01-debug-your-script/3-refactor/05.sh create mode 100755 01-debug-your-script/4-modify/01.sh create mode 100755 01-debug-your-script/4-modify/02.sh create mode 100755 01-debug-your-script/4-modify/03.sh create mode 100755 01-debug-your-script/4-modify/04.sh create mode 100755 01-debug-your-script/4-modify/05.sh create mode 100755 01-debug-your-script/5-chunks/01.sh create mode 100755 01-debug-your-script/5-chunks/02.sh create mode 100755 01-debug-your-script/5-chunks/03.sh create mode 100755 01-debug-your-script/5-chunks/04.sh create mode 100755 01-debug-your-script/5-chunks/05.sh create mode 100755 01-debug-your-script/6-blank-pages/01.sh create mode 100755 01-debug-your-script/6-blank-pages/02.sh create mode 100755 01-debug-your-script/6-blank-pages/03.sh create mode 100755 01-debug-your-script/6-blank-pages/04.sh create mode 100755 01-debug-your-script/6-blank-pages/05.sh diff --git a/01-debug-your-script/0-examples/00.md b/01-debug-your-script/0-examples/00.md new file mode 100644 index 0000000..f889e48 --- /dev/null +++ b/01-debug-your-script/0-examples/00.md @@ -0,0 +1,24 @@ +# How to Debug Your Bash Script + +## Overview + +Debugging is the process of identifying and removing errors and/or bugs from a script. +For Bash scripts, one helpful tool for debugging is `shellcheck`. + +### Using `shellcheck` + +- You can use the browser version of shellcheck at [ShellCheck.net](https://www.shellcheck.net/). +- To install shellcheck, visit the [ShellCheck GitHub repository](https://github.com/koalaman/shellcheck) and follow the instructions. +- It can also be used as a plugin (ShellCheck) for various editors including VS Code. + +To run shellcheck from the command line, use the following command: + +```bash +shellcheck 1.sh +``` + +### Limitations of `shellcheck` + +- It cannot detect issues with the environment that the script is running in. +- It cannot detect how the permissions are set on the file. +- It won't be able to tell you if specific packages are required to run the script. diff --git a/01-debug-your-script/0-examples/01.md b/01-debug-your-script/0-examples/01.md new file mode 100644 index 0000000..47a4c88 --- /dev/null +++ b/01-debug-your-script/0-examples/01.md @@ -0,0 +1,59 @@ +# Common Error Types in Bash Scripting + +When writing Bash scripts, it's common to encounter various types of errors. Understanding these errors and how to address them is crucial for successful script execution. Below are some of the most common error types along with examples and solutions: + +## 1. Syntax Errors + +Syntax errors occur due to mistakes in the script's syntax, leading to unexpected behavior or failure to execute. + +**Example:** + +```bash +Syntax Error: unexpected end of file +``` + +## 2. Not Found Errors + +Not found errors occur when the script attempts to access a non-existent file or directory. + +**Example:** + +```bash +No such file or directory +``` + +## 3. File Exists Errors + +File exists errors occur when the script tries to create a file or directory that already exists. + +**Example:** + +```bash +File exists +``` + +## 4. Permission Denied Errors + +Permission denied errors arise when the script lacks the necessary permissions for a specific operation. + +**Example:** + +```bash +Permission denied +``` + +**Solution:** +This error can often be resolved by using the `sudo` command before the operation that requires elevated permissions. + +## 5. Command Not Found Errors + +Command not found errors occur when the script attempts to execute a command that is not in the system's PATH. + +**Example:** + +```bash +Command not found +``` + +**Solution:** +Ensure that the command is installed on the system or provide the full path to the command in the script. diff --git a/01-debug-your-script/0-examples/01.sh b/01-debug-your-script/0-examples/01.sh new file mode 100755 index 0000000..baea7b8 --- /dev/null +++ b/01-debug-your-script/0-examples/01.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-13 +# Modified: 2024-03-14 +# Description: Common error types in Bash +# Usage: ./01.sh + +#------------------------------------------------------------------# + +# 1. Syntax Errors + +# Example of Syntax Error: +# echo "Hello World # Syntax error: missing closing double quote + +# 2. Not Found Errors + +# Example of Not Found Error: Attempting to access a non-existent directory +ls /non_existent_directory # No such file or directory + +# 3. File Exists Errors + +# Example of File Exists Error: Attempting to create a file that already exists +touch 01.sh # File exists + +# 4. Permission Denied Errors + +# Example of Permission Denied Error: Attempting to write to a directory without proper permissions +echo "Hello" >/root/test.txt # Permission denied + +# 5. Command Not Found Errors + +# Example of Command Not Found Error: Typo in the command +hello # Command not found + +# Ensure that the command is correctly spelled or installed + +#------------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/0-examples/02.md b/01-debug-your-script/0-examples/02.md new file mode 100755 index 0000000..7688bc0 --- /dev/null +++ b/01-debug-your-script/0-examples/02.md @@ -0,0 +1,56 @@ +# Finding Help in Bash + +When working with Bash scripts, knowing how to find help for commands and understanding different types of commands is essential for efficient script development and troubleshooting. + +## Finding Help + +There are several methods to find help for commands in Bash: + +- **Using the `man` Command**: The `man` command displays the manual page for a given command. + +- **Using the `help` Command**: The `help` command provides help information for shell built-in commands. + +- **Using the `info` Command**: The `info` command displays detailed information (info page) for a given command. + +### Types of Commands + +Commands in Bash can be categorized into two main types: + +1. **Internal Commands**: These are commands built into the shell itself, such as `echo`. + +2. **External Commands**: These are commands that are not built into the shell and typically reside in separate executable files, such as `ls` + +### Determining Command Types + +To determine the type of a command, you can use the `type` command: + +```bash +type -a echo # echo is a shell builtin +``` + +The `-a` option displays all information about the command, including its type. + +### Using the `help` Command + +The `help` command is specifically designed to provide help information for `shell built-in commands`. Here are some useful options: + +- `help `: Display help information for the specified command. +- `help -d `: Display the short description of the command. +- `help -s `: Display the syntax of the command. + +### Using the `man` Command + +The `man` command is used to display the manual page for `external commands`. It offers several options: + +- `man `: Display the manual page for the specified command. +- `man -k `: Search for manual pages containing the specified keyword. +- `man -K `: Display the manual page for the specified keyword (more detailed). + +### Using the `info` Command + +The `info` command provides detailed information (info page) for `external commands`. Here are some options: + +- `info `: Display the info page for the specified command. +- `info -d `: Display the short description of the command. +- `info -s `: Display the syntax of the command. +- `info -k `: Search for info pages containing the specified keyword. diff --git a/01-debug-your-script/0-examples/02.sh b/01-debug-your-script/0-examples/02.sh new file mode 100755 index 0000000..5946d36 --- /dev/null +++ b/01-debug-your-script/0-examples/02.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: Finding help in Bash +# Usage: ./02.sh + +#------------------------------------------------------------# + +# There are several ways to find help in Bash +# 1. help Command +# 2. man command +# 3. info command + +# Which one to use depnds on the type of command and the level of detail required +# There are two types of commands: Internal and External, we can use the `type` command +# to determine the type of a command + +# Internal Commands +type -a echo # Determine the type of the 'echo' command + +# External Commands +type -a ls # Determine the type of the 'ls' command + +# we use `help` command with the `internal commands` +# we use `man` and `info` command with the `external commands` + +# both `man` and `info` provide documentation for commands and programs. +# `man` command offer a simpler, text-based interface with essential information. +# `info` command provide a more structured, hierarchical format with comprehensive documentation, +# particularly for GNU software. +# The choice between `man` and `info` depends on the specific documentation available for +# the command or program you are interested in and your preferred style of navigation and presentation. + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/0-examples/03.sh b/01-debug-your-script/0-examples/03.sh new file mode 100755 index 0000000..2b0daec --- /dev/null +++ b/01-debug-your-script/0-examples/03.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: the help command +# Usage: ./03.sh + +#------------------------------------------------------------# + +# The `help` command is used with Internal Commands(built-in command) in Bash. +# Example: Display help information for the 'echo' command +echo "Displaying help information for the 'echo' command:" +help echo + +# Example: Displaying syntax of the 'echo' command +echo "Displaying syntax of the 'echo' command:" +help -s echo + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/0-examples/04.sh b/01-debug-your-script/0-examples/04.sh new file mode 100755 index 0000000..940a5a3 --- /dev/null +++ b/01-debug-your-script/0-examples/04.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: the man command +# Usage: ./04.sh + +#------------------------------------------------------------# + +# Example: Display the manual page for the 'ls' command +echo "Displaying the manual page for the 'ls' command:" +man ls + +# Example: Search for manual pages containing the keyword 'ls' +echo "Searching for manual pages containing the keyword 'ls':" +man -k ls + +# Example: Display the manual page for the keyword 'ls' (more detailed) +echo "Displaying the manual page for the keyword 'ls' (more detailed):" +man -K ls + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/0-examples/05.sh b/01-debug-your-script/0-examples/05.sh new file mode 100755 index 0000000..56697bd --- /dev/null +++ b/01-debug-your-script/0-examples/05.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: the info command +# Usage: ./05.sh + +#------------------------------------------------------------# + +# Example: Display the info page for the 'ls' command +echo "Displaying the info page for the 'ls' command:" +info ls + +# Example: Displaying short description of the 'ls' command +echo "Displaying short description of the 'ls' command:" +info -d ls + +# Example: Displaying syntax of the 'ls' command +echo "Displaying syntax of the 'ls' command:" +info -s ls + +# Example: Search for info pages containing the keyword 'ls' +echo "Searching for info pages containing the keyword 'ls':" +info -k ls + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/1-blanks/01.sh b/01-debug-your-script/1-blanks/01.sh new file mode 100755 index 0000000..68abc0f --- /dev/null +++ b/01-debug-your-script/1-blanks/01.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Author: ________ +# Date: __________ +# Modified: ___________ +# Description: Common error types in Bash +# Usage: ./01.sh + +#------------------------------------------------------------------# + +# 1. Syntax Errors + +# Example of Syntax Error: +# echo "Hello World # Syntax error: __________ + +# 2. Not Found Errors + +# Example of Not Found Error: Attempting to access a non-existent _________ +ls _________ # _____________ + +# 3. File Exists Errors + +# Example of File Exists Error: Attempting to create a file that already ________ +touch ________ # ________ + +# 4. Permission Denied Errors + +# Example of Permission Denied Error: Attempting to write to a directory without proper __________ +echo "Hello" >/root/test.txt # ______________ + +# 5. Command Not Found Errors + +# Example of Command Not Found Error: ________ in the ________ +hello # _______________ + +# Ensure that the command is correctly spelled or installed + +#------------------------------------------------------------------# + +exit 0 + + diff --git a/01-debug-your-script/1-blanks/02.sh b/01-debug-your-script/1-blanks/02.sh new file mode 100755 index 0000000..8647d4d --- /dev/null +++ b/01-debug-your-script/1-blanks/02.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Author: ________ +# Date: __________ +# Modified: ___________ +# Description: Finding help in Bash +# Usage: ./02.sh + +#------------------------------------------------------------# + +# There are several ways to find help in Bash +# 1. ______ Command +# 2. ______ command +# 3. ______ command + +# Which one to use depends on the type of command and the level of detail required +# There are two types of commands: Internal and External, we can use the `type` command +# to determine the type of a command + +# Internal Commands +type -a echo # Determine the type of the 'echo' command + +# External Commands +type -a ls # Determine the type of the 'ls' command + +# we use `help` command with the `internal commands` +# we use `man` and `info` command with the `external commands` + +# both `man` and `info` provide documentation for commands and programs. +# `man` command offer a simpler, text-based interface with essential information. +# `info` command provide a more structured, hierarchical format with comprehensive documentation, +# particularly for GNU software. +# The choice between `man` and `info` depends on the specific documentation available for +# the command or program you are interested in and your preferred style of navigation and presentation. + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/1-blanks/03.sh b/01-debug-your-script/1-blanks/03.sh new file mode 100755 index 0000000..605ad58 --- /dev/null +++ b/01-debug-your-script/1-blanks/03.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Author: ________ +# Date: __________ +# Modified: ___________ +# Description: the help command +# Usage: ./03.sh + +#------------------------------------------------------------# + +# The `help` command is used with ________ Commands(built-in command) in Bash. +# Example: Display help information for the 'echo' command +echo "Displaying help information for the 'echo' command:" +____ echo + +# Example: Displaying syntax of the 'echo' command +echo "Displaying syntax of the 'echo' command:" +____ -s echo + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/1-blanks/04.sh b/01-debug-your-script/1-blanks/04.sh new file mode 100755 index 0000000..119f613 --- /dev/null +++ b/01-debug-your-script/1-blanks/04.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Author: ________ +# Date: __________ +# Modified: ___________ +# Description: the man command +# Usage: ./04.sh + +#------------------------------------------------------------# + +# Example: Display the manual page for the 'ls' command +echo "Displaying the manual page for the 'ls' command:" +____ ls + +# Example: Search for manual pages containing the keyword 'ls' +echo "Searching for manual pages containing the keyword 'ls':" +man -___ ls + +# Example: Display the manual page for the keyword 'ls' (more detailed) +echo "Displaying the manual page for the keyword 'ls' (more detailed):" +man -__ ls + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/1-blanks/05.sh b/01-debug-your-script/1-blanks/05.sh new file mode 100755 index 0000000..a8b668f --- /dev/null +++ b/01-debug-your-script/1-blanks/05.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Author: ________ +# Date: __________ +# Modified: ___________ +# Description: the info command +# Usage: ./05.sh + +#------------------------------------------------------------# + +# Example: Display the info page for the 'ls' command +echo "Displaying the info page for the 'ls' command:" +____ ls + +# Example: Displaying short description of the 'ls' command +echo "Displaying short description of the 'ls' command:" +info -___ ls + +# Example: Displaying syntax of the 'ls' command +echo "Displaying syntax of the 'ls' command:" +info -___ ls + +# Example: Search for info pages containing the keyword 'ls' +echo "Searching for info pages containing the keyword 'ls':" +info -___ ls + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/1.sh b/01-debug-your-script/1.sh deleted file mode 100644 index e4bfe9d..0000000 --- a/01-debug-your-script/1.sh +++ /dev/null @@ -1,107 +0,0 @@ -#!/bin/bash - -# Author: Samir M. -# Date: 2024-03-12 -# Modified: 2024-03-12 -# Description: How to debug your script -# Usage: ./01.sh - -# Debugging : is the process of identifying and removing errors or bugs from a script. -# To debug our scripts we will use very nice tool called `shellchek` -# 1. You can use the browser version of shellcheck at https://www.shellcheck.net/ -# 2. From the command line, To install shellcheck go to https://github.com/koalaman/shellcheck and follow the instructions. -# 3. As a plugin for various editors including VS code. - -# To run shellcheck from the command line, use the following command: -###### shellcheck 1.sh ###### - -# echo is a command that prints values to the terminal. -echo "Hello, World!" -echo "Hello, from bash scripting!" - -# Shellcheck has some limitations: -# It can't detect the issue with the environment that the script is running in. -# It can't detect how the permissions are set on the file. -# It won't be able to tell you if you need specific pachages is required to run the script. - - -# Error message -$ ls folder -# ls: cannot access 'file': No such file or directory -# Explanation: The 'ls' command encountered an error while trying to access the file named 'file'. -# Error Message: cannot access 'file' -# Error Reason: No such file or directory - -# Most common errors: -# 1. Syntax errors - -# Example: -# Syntax Error: unexpected end of file - -# 2. Not found errors - -# Example: -# No such file or directory - - -# 3. file exists errors - -# Example: -# File exists - -# 4. Permission denied errors - -# Example: -# Permission denied -# Most of the time is fixed using sudo command before the command that is giving the error. - -# 5. command not found errors - -# Example: -# Command not found - - -# How to find help : - -# 1. Use the `man` command to find help for a command. -# 2. Use the `help` command to find help for a command. -# 3. Use the `info` command to find help for a command. - -# Type of commands: -# 1. Internal commands: These are commands that are built into the shell ex: help. -# 2. External commands: These are commands that are not built into the shell ex : man, info. - -# How to find the type of command: -# Use the `type` command to find the type of a command. - -# Example: - -type -a echo # echo is a shell builtin -# -a : option is used to display all information about the command. - -# How to use the `help` command: -# help : to display the help information for the command. -# help -d : to display the short description of the command. -# help -s : to display the syntax of the command. - -# How to use `man` command -# man : to display the manual page for the command. -# man -k : to display the manual page for the command -# man -K : to display the manual page for the command (more detailed than -k option) - -# How to use `info` command - -# info : to display the info page for the command. -# info -d : to display the short description of the command. -# info -s : to display the syntax of the command. -# info -k : to display the info page for the command. - - -# Example: -help echo - - -exit 0 - - - diff --git a/01-debug-your-script/2-bugs/01.sh b/01-debug-your-script/2-bugs/01.sh new file mode 100755 index 0000000..0715c88 --- /dev/null +++ b/01-debug-your-script/2-bugs/01.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-13 +# Modified: 2024-03-14 +# Description: Common error types in Bash +# Usage: ./01.sh + +#------------------------------------------------------------------# + +# 1. Syntax Errors + +# Example of Syntax Error: +echo "Hello World # Syntax error: missing closing double quote + +# 2. Not Found Errors + +# Example of Not Found Error: Attempting to access a non-existent directory +ls /non_existent_directory # No such file or directory + +# 3. File Exists Errors + +# Example of File Exists Error: Attempting to create a file that already exists +touch 01.sh # File exists + +# 4. Permission Denied Errors + +# Example of Permission Denied Error: Attempting to write to a directory without proper permissions +echo "Hello" >/root/test.txt # Permission denied + +# 5. Command Not Found Errors + +# Example of Command Not Found Error: Typo in the command +hello # Command not found + +# Ensure that the command is correctly spelled or installed + +#------------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/2-bugs/02.sh b/01-debug-your-script/2-bugs/02.sh new file mode 100755 index 0000000..3cfbcca --- /dev/null +++ b/01-debug-your-script/2-bugs/02.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: Finding help in Bash +# Usage: ./02.sh + +#------------------------------------------------------------# + +# There are several ways to find help in Bash +# 1. help Command +# 2. man command +# 3. info command + +# Which one to use depends on the type of command and the level of detail required. +# There are two types of commands: Internal and External. We can use the `type` command +# to determine the type of a command. + +# Internal Commands +types -a echo # Determine the type of the 'echo' command + +# External Commands +type -a lss # Determine the type of the 'ls' command + +# we use `help` command with the `internal commands` +# we use `man` and `info` command with the `external commands` + +# both `man` and `info` provide documentation for commands and programs. +# `man` command offer a simpler, text-based interface with essential information. +# `info` command provide a more structured, hierarchical format with comprehensive documentation, +# particularly for GNU software. +# The choice between `man` and `info` depends on the specific documentation available for +# the command or program you are interested in and your preferred style of navigation and presentation. + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/2-bugs/03.sh b/01-debug-your-script/2-bugs/03.sh new file mode 100755 index 0000000..9d938be --- /dev/null +++ b/01-debug-your-script/2-bugs/03.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: the help command +# Usage: ./03.sh + +#------------------------------------------------------------# + +# The `help` command is used with Internal Commands(built-in command) in Bash. +# Example: Display help information for the 'echo' command +echo "Displaying help information for the 'echo' command:" +helpp echo + +# Example: Displaying syntax of the 'echo' command +echo "Displaying syntax of the 'echo' command:" +help -s echoo + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/2-bugs/04.sh b/01-debug-your-script/2-bugs/04.sh new file mode 100755 index 0000000..cd47dbb --- /dev/null +++ b/01-debug-your-script/2-bugs/04.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: the man command +# Usage: ./04.sh + +#------------------------------------------------------------# + +# Example: Display the manual page for the 'ls' command +echo "Displaying the manual page for the 'ls' command:" +mann ls + +# Example: Search for manual pages containing the keyword 'ls' +echo "Searching for manual pages containing the keyword 'ls':" +man -kk ls + +# Example: Display the manual page for the keyword 'ls' (more detailed) +echo "Displaying the manual page for the keyword 'ls' (more detailed):" +man -Kk ls + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/2-bugs/05.sh b/01-debug-your-script/2-bugs/05.sh new file mode 100755 index 0000000..d8f0594 --- /dev/null +++ b/01-debug-your-script/2-bugs/05.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: the info command +# Usage: ./05.sh + +#------------------------------------------------------------# + +# Example: Display the info page for the 'ls' command +echo "Displaying the info page for the 'ls' command:" +inf ls + +# Example: Displaying short description of the 'ls' command +echo "Displaying short description of the 'ls' command:" +info -dd ls + +# Example: Displaying syntax of the 'ls' command +echo "Displaying syntax of the 'ls' command:" +info -ss ls + +# Example: Search for info pages containing the keyword 'ls' +echo "Searching for info pages containing the keyword 'ls':" +info -kk ls + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/3-refactor/01.sh b/01-debug-your-script/3-refactor/01.sh new file mode 100755 index 0000000..baea7b8 --- /dev/null +++ b/01-debug-your-script/3-refactor/01.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-13 +# Modified: 2024-03-14 +# Description: Common error types in Bash +# Usage: ./01.sh + +#------------------------------------------------------------------# + +# 1. Syntax Errors + +# Example of Syntax Error: +# echo "Hello World # Syntax error: missing closing double quote + +# 2. Not Found Errors + +# Example of Not Found Error: Attempting to access a non-existent directory +ls /non_existent_directory # No such file or directory + +# 3. File Exists Errors + +# Example of File Exists Error: Attempting to create a file that already exists +touch 01.sh # File exists + +# 4. Permission Denied Errors + +# Example of Permission Denied Error: Attempting to write to a directory without proper permissions +echo "Hello" >/root/test.txt # Permission denied + +# 5. Command Not Found Errors + +# Example of Command Not Found Error: Typo in the command +hello # Command not found + +# Ensure that the command is correctly spelled or installed + +#------------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/3-refactor/02.sh b/01-debug-your-script/3-refactor/02.sh new file mode 100755 index 0000000..5946d36 --- /dev/null +++ b/01-debug-your-script/3-refactor/02.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: Finding help in Bash +# Usage: ./02.sh + +#------------------------------------------------------------# + +# There are several ways to find help in Bash +# 1. help Command +# 2. man command +# 3. info command + +# Which one to use depnds on the type of command and the level of detail required +# There are two types of commands: Internal and External, we can use the `type` command +# to determine the type of a command + +# Internal Commands +type -a echo # Determine the type of the 'echo' command + +# External Commands +type -a ls # Determine the type of the 'ls' command + +# we use `help` command with the `internal commands` +# we use `man` and `info` command with the `external commands` + +# both `man` and `info` provide documentation for commands and programs. +# `man` command offer a simpler, text-based interface with essential information. +# `info` command provide a more structured, hierarchical format with comprehensive documentation, +# particularly for GNU software. +# The choice between `man` and `info` depends on the specific documentation available for +# the command or program you are interested in and your preferred style of navigation and presentation. + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/3-refactor/03.sh b/01-debug-your-script/3-refactor/03.sh new file mode 100755 index 0000000..2b0daec --- /dev/null +++ b/01-debug-your-script/3-refactor/03.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: the help command +# Usage: ./03.sh + +#------------------------------------------------------------# + +# The `help` command is used with Internal Commands(built-in command) in Bash. +# Example: Display help information for the 'echo' command +echo "Displaying help information for the 'echo' command:" +help echo + +# Example: Displaying syntax of the 'echo' command +echo "Displaying syntax of the 'echo' command:" +help -s echo + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/3-refactor/04.sh b/01-debug-your-script/3-refactor/04.sh new file mode 100755 index 0000000..940a5a3 --- /dev/null +++ b/01-debug-your-script/3-refactor/04.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: the man command +# Usage: ./04.sh + +#------------------------------------------------------------# + +# Example: Display the manual page for the 'ls' command +echo "Displaying the manual page for the 'ls' command:" +man ls + +# Example: Search for manual pages containing the keyword 'ls' +echo "Searching for manual pages containing the keyword 'ls':" +man -k ls + +# Example: Display the manual page for the keyword 'ls' (more detailed) +echo "Displaying the manual page for the keyword 'ls' (more detailed):" +man -K ls + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/3-refactor/05.sh b/01-debug-your-script/3-refactor/05.sh new file mode 100755 index 0000000..56697bd --- /dev/null +++ b/01-debug-your-script/3-refactor/05.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: the info command +# Usage: ./05.sh + +#------------------------------------------------------------# + +# Example: Display the info page for the 'ls' command +echo "Displaying the info page for the 'ls' command:" +info ls + +# Example: Displaying short description of the 'ls' command +echo "Displaying short description of the 'ls' command:" +info -d ls + +# Example: Displaying syntax of the 'ls' command +echo "Displaying syntax of the 'ls' command:" +info -s ls + +# Example: Search for info pages containing the keyword 'ls' +echo "Searching for info pages containing the keyword 'ls':" +info -k ls + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/4-modify/01.sh b/01-debug-your-script/4-modify/01.sh new file mode 100755 index 0000000..1386218 --- /dev/null +++ b/01-debug-your-script/4-modify/01.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-13 +# Modified: 2024-03-14 +# Description: Common error types in Bash +# Usage: ./01.sh + +#------------------------------------------------------------------# + +# 1. Syntax Errors + +# Example of Syntax Error: +# echo "Hello World # Syntax error: missing closing double quote + +# 2. Not Found Errors + +# Example of Not Found Error: Attempting to access a non-existent directory +lf /non_existent_directory # No such file or directory + +# 3. File Exists Errors + +# Example of File Exists Error: Attempting to create a file that already exists +touch 01.sh # File exists + +# 4. Permission Denied Errors + +# Example of Permission Denied Error: Attempting to write to a directory without proper permissions +echo "Hello" < /root/test.txt # Permission denied + +# 5. Command Not Found Errors + +# Example of Command Not Found Error: Typo in the command +hello # Command not found + +# Ensure that the command is correctly spelled or installed + +#------------------------------------------------------------------# + +chmod 444 "$0" + +exit 0 diff --git a/01-debug-your-script/4-modify/02.sh b/01-debug-your-script/4-modify/02.sh new file mode 100755 index 0000000..b8cf770 --- /dev/null +++ b/01-debug-your-script/4-modify/02.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: Finding help in Bash +# Usage: ./02.sh + +#------------------------------------------------------------# + +# There are several ways to find help in Bash +# 1. help Command +# 2. man command +# 3. info command + +# Which one to use depends on the type of command and the level of detail required +# There are two types of commands: Internal and External, we can use the `type` command +# to determine the type of a command + +# Internal Commands +typ -a echo # Determine the type of the 'echo' command + +# External Commands +type -a ls # Determine the type of the 'ls' command + +# we use `help` command with the `internal commands` +# we use `man` and `info` command with the `external commands` + +# both `man` and `info` provide documentation for commands and programs. +# `man` command offers a simpler, text-based interface with essential information. +# `info` command provides a more structured, hierarchical format with comprehensive documentation, +# particularly for GNU software. +# The choice between `man` and `info` depends on the specific documentation available for +# the command or program you are interested in and your preferred style of navigation and presentation. + +#------------------------------------------------------------# + +# Make the script read-only to prevent modifications by students +# This command sets read-only permissions for the script +chmod 444 "$0" + +exit 0 diff --git a/01-debug-your-script/4-modify/03.sh b/01-debug-your-script/4-modify/03.sh new file mode 100755 index 0000000..0a08426 --- /dev/null +++ b/01-debug-your-script/4-modify/03.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: the help command +# Usage: ./03.sh + +#------------------------------------------------------------# + +# The `help` command is used with Internal Commands(built-in command) in Bash. +# Example: Display help information for the 'echo' command +echo "Displaying help information for the 'echo' command:" +hel echo + +# Example: Displaying syntax of the 'echo' command +echo "Displaying syntax of the 'echo' command:" +help -j echo + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/4-modify/04.sh b/01-debug-your-script/4-modify/04.sh new file mode 100755 index 0000000..c1b7ec9 --- /dev/null +++ b/01-debug-your-script/4-modify/04.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: the man command +# Usage: ./04.sh + +#------------------------------------------------------------# + +# Example: Display the manual page for the 'ls' command +echo "Displaying the manual page for the 'ls' command:" +man ls + +# Example: Search for manual pages containing the keyword 'ls' +echo "Searching for manual pages containing the keyword 'ls':" +man -f ls + +# Example: Display the manual page for the keyword 'ls' (more detailed) +echo "Displaying the manual page for the keyword 'ls' (more detailed):" +ma -K ls + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/4-modify/05.sh b/01-debug-your-script/4-modify/05.sh new file mode 100755 index 0000000..83c527a --- /dev/null +++ b/01-debug-your-script/4-modify/05.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: the info command +# Usage: ./05.sh + +#------------------------------------------------------------# + +# Example: Display the info page for the 'ls' command +echo "Displaying the info page for the 'ls' command:" +info ls + +# Example: Displaying short description of the 'ls' command +echo "Displaying short description of the 'ls' command:" +info -m ls + +# Example: Displaying syntax of the 'ls' command +echo "Displaying syntax of the 'ls' command:" +info -s ls + +# Example: Search for info pages containing the keyword 'ls' +echo "Searching for info pages containing the keyword 'ls':" +info -t ls + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/5-chunks/01.sh b/01-debug-your-script/5-chunks/01.sh new file mode 100755 index 0000000..8e91200 --- /dev/null +++ b/01-debug-your-script/5-chunks/01.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-13 +# Modified: 2024-03-14 +# Description: Common error types in Bash +# Usage: ./01.sh + +#------------------------------------------------------------------# + +# 1. Syntax Errors + +# Example of Syntax Error: +# echo "Hello World # Syntax error: missing closing double quote + +# 2. Not Found Errors + +# Example of Not Found Error: Attempting to access a non-existent directory + +# 3. File Exists Errors + +# Example of File Exists Error: Attempting to create a file that already exists + +# 4. Permission Denied Errors + +# Example of Permission Denied Error: Attempting to write to a directory without proper permissions +echo "Hello" >/root/test.txt # Permission denied + +# 5. Command Not Found Errors + +# Example of Command Not Found Error: Typo in the command +hello # Command not found + +# Ensure that the command is correctly spelled or installed + +#------------------------------------------------------------------# diff --git a/01-debug-your-script/5-chunks/02.sh b/01-debug-your-script/5-chunks/02.sh new file mode 100755 index 0000000..ce81e1d --- /dev/null +++ b/01-debug-your-script/5-chunks/02.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: Finding help in Bash +# Usage: ./02.sh + +#------------------------------------------------------------# + +# There are several ways to find help in Bash +# 1. help Command +# 2. man command +# 3. info command + +# Which one to use depnds on the type of command and the level of detail required +# There are two types of commands: Internal and External, we can use the `type` command +# to determine the type of a command + +# Internal Commands + +# External Commands + +# we use `help` command with the `internal commands` +# we use `man` and `info` command with the `external commands` + +# both `man` and `info` provide documentation for commands and programs. +# `man` command offer a simpler, text-based interface with essential information. +# `info` command provide a more structured, hierarchical format with comprehensive documentation, +# particularly for GNU software. +# The choice between `man` and `info` depends on the specific documentation available for +# the command or program you are interested in and your preferred style of navigation and presentation. + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/5-chunks/03.sh b/01-debug-your-script/5-chunks/03.sh new file mode 100755 index 0000000..f59f136 --- /dev/null +++ b/01-debug-your-script/5-chunks/03.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: the help command +# Usage: ./03.sh + +#------------------------------------------------------------# + +# The `help` command is used with Internal Commands(built-in command) in Bash. +# Example: Display help information for the 'echo' command +echo "Displaying help information for the 'echo' command:" +help echo + +# Example: Displaying syntax of the 'echo' command + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/5-chunks/04.sh b/01-debug-your-script/5-chunks/04.sh new file mode 100755 index 0000000..bd2e913 --- /dev/null +++ b/01-debug-your-script/5-chunks/04.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: the man command +# Usage: ./04.sh + +#------------------------------------------------------------# + +# Example: Display the manual page for the 'ls' command +echo "Displaying the manual page for the 'ls' command:" +man ls + +# Example: Search for manual pages containing the keyword 'ls' + +# Example: Display the manual page for the keyword 'ls' (more detailed) + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/5-chunks/05.sh b/01-debug-your-script/5-chunks/05.sh new file mode 100755 index 0000000..36d915d --- /dev/null +++ b/01-debug-your-script/5-chunks/05.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: the info command +# Usage: ./05.sh + +#------------------------------------------------------------# + +# Example: Display the info page for the 'ls' command + +# Example: Displaying short description of the 'ls' command +echo "Displaying short description of the 'ls' command:" +info -d ls + +# Example: Displaying syntax of the 'ls' command + +# Example: Search for info pages containing the keyword 'ls' +echo "Searching for info pages containing the keyword 'ls':" +info -k ls + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/6-blank-pages/01.sh b/01-debug-your-script/6-blank-pages/01.sh new file mode 100755 index 0000000..f17ef17 --- /dev/null +++ b/01-debug-your-script/6-blank-pages/01.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-13 +# Modified: 2024-03-14 +# Description: Common error types in Bash +# Usage: ./01.sh + +#------------------------------------------------------------------# + +#------------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/6-blank-pages/02.sh b/01-debug-your-script/6-blank-pages/02.sh new file mode 100755 index 0000000..80e3858 --- /dev/null +++ b/01-debug-your-script/6-blank-pages/02.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: Finding help in Bash +# Usage: ./02.sh + +#------------------------------------------------------------# + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/6-blank-pages/03.sh b/01-debug-your-script/6-blank-pages/03.sh new file mode 100755 index 0000000..a7840d5 --- /dev/null +++ b/01-debug-your-script/6-blank-pages/03.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: the help command +# Usage: ./03.sh + +#------------------------------------------------------------# + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/6-blank-pages/04.sh b/01-debug-your-script/6-blank-pages/04.sh new file mode 100755 index 0000000..a489bec --- /dev/null +++ b/01-debug-your-script/6-blank-pages/04.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: the man command +# Usage: ./04.sh + +#------------------------------------------------------------# + +#------------------------------------------------------------# + +exit 0 diff --git a/01-debug-your-script/6-blank-pages/05.sh b/01-debug-your-script/6-blank-pages/05.sh new file mode 100755 index 0000000..a67e1f9 --- /dev/null +++ b/01-debug-your-script/6-blank-pages/05.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Author: Samir M. +# Date: 2024-03-14 +# Modified: 2024-03-14 +# Description: the info command +# Usage: ./05.sh + +#------------------------------------------------------------# + +#------------------------------------------------------------# + +exit 0