From 6d70d960a90e4c6337a4d531bc2bc0ff836630f6 Mon Sep 17 00:00:00 2001
From: Muh Yusuf <79491810+yusuf601@users.noreply.github.com>
Date: Sun, 11 Aug 2024 20:39:13 +0700
Subject: [PATCH 1/8] Update README.md
---
README.md | 81 ++++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 66 insertions(+), 15 deletions(-)
diff --git a/README.md b/README.md
index 27afa2f..1d26268 100644
--- a/README.md
+++ b/README.md
@@ -1,15 +1,26 @@
+ # Bash Guide
+
+This comprehensive guide provides an introduction to Bash scripting and command-line operations. Whether you're a beginner or an experienced user, this guide offers valuable insights into Bash syntax, shell programming, and useful tricks to enhance your command-line productivity.
+
+## Who is this guide for?
+
+- Beginners looking to learn Bash scripting
+- Intermediate users wanting to improve their shell programming skills
+- Advanced users seeking a quick reference or new tricks
+
+Let's dive in and explore the power of Bash!
## Table of Contents
1. [Basic Operations](#1-basic-operations)
- 1.1. [File Operations](#11-file-operations)
+ 1.1. [File Operations](#11-file-operations)
1.2. [Text Operations](#12-text-operations)
1.3. [Directory Operations](#13-directory-operations)
1.4. [SSH, System Info & Network Operations](#14-ssh-system-info--network-operations)
1.5. [Process Monitoring Operations](#15-process-monitoring-operations)
- 2. [Basic Shell Programming](#2-basic-shell-programming)
+ 3. [Basic Shell Programming](#2-basic-shell-programming)
2.1. [Variables](#21-variables)
2.2. [Array](#22-array)
2.3. [String Substitution](#23-string-substitution)
@@ -19,9 +30,9 @@
2.7. [Loops](#27-loops)
2.8. [Regex](#28-regex)
2.9. [Pipes](#29-pipes)
- 3. [Tricks](#3-tricks)
- 4. [Debugging](#4-debugging)
- 5. [Multi-threading](#5-multi-threading)
+ 4. [Tricks](#3-tricks)
+ 5. [Debugging](#4-debugging)
+ 6. [Multi-threading](#5-multi-threading)
# 1. Basic Operations
@@ -972,27 +983,67 @@ nohup command &
# 2. Basic Shell Programming
+Bash scripting allows you to automate tasks and create powerful command-line tools. This section covers the fundamental concepts of shell programming.
+
+## 2.1. Shebang
-The first line that you will write in bash script files is called `shebang`. This line in any script determines the script's ability to be executed like a standalone executable without typing sh, bash, python, php etc beforehand in the terminal.
+The first line of a Bash script, known as the "shebang", determines how the script should be executed:
```bash
#!/usr/bin/env bash
-```
-## 2.1. Variables
+## 2.2. Variables
-Creating variables in bash is similar to other languages. There are no data types. A variable in bash can contain a number, a character, a string of characters, etc. You have no need to declare a variable, just assigning a value to its reference will create it.
+In Bash, variables are used to store data. Unlike many programming languages, Bash doesn't require you to declare a variable's type. Here's how to work with variables:
+
+### Creating Variables
+
+To create a variable, simply assign a value to a name:
-Example:
```bash
-str="hello world"
-```
+name="John Doe"
+age=30
+PI=3.14159
-The above line creates a variable `str` and assigns "hello world" to it. The value of variable is retrieved by putting the `$` in the beginning of variable name.
+### Creating and Using Variables
+
+To create a variable, assign a value to a name. To use a variable, prefix its name with a dollar sign ($):
-Example:
```bash
-echo $str # hello world
+# Creating variables
+name="John Doe"
+age=30
+PI=3.14159
+
+# Using variables
+echo "Hello, $name! You are $age years old."
+echo "Pi is approximately $PI"
+
+# Command substitution
+current_date=$(date +%Y-%m-%d)
+file_count=$(ls | wc -l)
+
+# Arithmetic operations
+x=5
+y=3
+sum=$((x + y))
+product=$((x * y))
+
+# Read-only variables
+readonly CONSTANT_VALUE=100
+
+# Unsetting variables
+unset variable_name
+
+# Local variables in functions
+function example_function() {
+ local local_var="I'm local"
+ echo "$local_var"
+}
+
+# Always quote your variables when using them
+file_name="My Document.txt"
+cat "$file_name" # Correct
```
## 2.2. Array
Like other languages bash has also arrays. An array is a variable containing multiple values. There's no maximum limit on the size of array. Arrays in bash are zero based. The first element is indexed with element 0. There are several ways for creating arrays in bash which are given below.
From 0ba0af2ab2da107d44f1906b0874e1049b7a54b5 Mon Sep 17 00:00:00 2001
From: Muh Yusuf <79491810+yusuf601@users.noreply.github.com>
Date: Sun, 11 Aug 2024 20:43:14 +0700
Subject: [PATCH 2/8] Update README.md
---
README.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 1d26268..488b40a 100644
--- a/README.md
+++ b/README.md
@@ -985,7 +985,7 @@ nohup command &
Bash scripting allows you to automate tasks and create powerful command-line tools. This section covers the fundamental concepts of shell programming.
-## 2.1. Shebang
+## 2.1.Variables
The first line of a Bash script, known as the "shebang", determines how the script should be executed:
From d55801b8700aea375b83db0685b9bae0d0e3cc3c Mon Sep 17 00:00:00 2001
From: Muh Yusuf <79491810+yusuf601@users.noreply.github.com>
Date: Sun, 11 Aug 2024 20:50:50 +0700
Subject: [PATCH 3/8] Update README.md
---
README.md | 2 --
1 file changed, 2 deletions(-)
diff --git a/README.md b/README.md
index 488b40a..a033aed 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,5 @@
- # Bash Guide
-
This comprehensive guide provides an introduction to Bash scripting and command-line operations. Whether you're a beginner or an experienced user, this guide offers valuable insights into Bash syntax, shell programming, and useful tricks to enhance your command-line productivity.
## Who is this guide for?
From bf144ddc72eb853d74babda5ed198b13084d6552 Mon Sep 17 00:00:00 2001
From: Muh Yusuf <79491810+yusuf601@users.noreply.github.com>
Date: Sun, 11 Aug 2024 20:51:47 +0700
Subject: [PATCH 4/8] Update README.md
---
README.md | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index a033aed..2d69480 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,7 @@
-This comprehensive guide provides an introduction to Bash scripting and command-line operations. Whether you're a beginner or an experienced user, this guide offers valuable insights into Bash syntax, shell programming, and useful tricks to enhance your command-line productivity.
+
+This comprehensive guide provides an introduction to Bash scripting and command-line operations. Whether you're a beginner or an experienced user, this guide offers valuable insights into Bash syntax, shell programming, and useful tricks to enhance your command-line productivity.
## Who is this guide for?
@@ -8,8 +9,7 @@ This comprehensive guide provides an introduction to Bash scripting and command-
- Intermediate users wanting to improve their shell programming skills
- Advanced users seeking a quick reference or new tricks
-Let's dive in and explore the power of Bash!
-
+Let's dive in and explore the power of Bash!
## Table of Contents
1. [Basic Operations](#1-basic-operations)
From 53c7580ab97f1992d78f2b0833d180388d71af1d Mon Sep 17 00:00:00 2001
From: Muh Yusuf <79491810+yusuf601@users.noreply.github.com>
Date: Sun, 11 Aug 2024 20:58:32 +0700
Subject: [PATCH 5/8] Update README.md
---
README.md | 45 +++++++++++++++++++++------------------------
1 file changed, 21 insertions(+), 24 deletions(-)
diff --git a/README.md b/README.md
index 2d69480..4ac4a3c 100644
--- a/README.md
+++ b/README.md
@@ -35,54 +35,51 @@ Let's dive in and explore the power of Bash!
# 1. Basic Operations
### a. `export`
-Displays all environment variables. If you want to get details of a specific variable, use `echo $VARIABLE_NAME`.
-```bash
+Displays all environment variables. To see the value of a specific variable, use `echo $VARIABLE_NAME`.
+
+Usage:
export
-```
+
Example:
-```bash
$ export
-AWS_HOME=/Users/adnanadnan/.aws
+AWS_HOME=/Users/yourname/.aws
LANG=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LESS=-R
$ echo $AWS_HOME
-/Users/adnanadnan/.aws
-```
+/Users/yourname/.aws
### b. `whatis`
-whatis shows description for user commands, system calls, library functions, and others in manual pages
-```bash
-whatis something
-```
+Shows a brief description for user commands, system calls, library functions, and others found in manual pages.
+
+Usage:
+whatis command_name
+
Example:
-```bash
$ whatis bash
bash (1) - GNU Bourne-Again SHell
-```
### c. `whereis`
-whereis searches for executables, source files, and manual pages using a database built by system automatically.
-```bash
+Searches for executables, source files, and manual pages using a database built by the system.
+
+Usage:
whereis name
-```
+
Example:
-```bash
$ whereis php
/usr/bin/php
-```
### d. `which`
-which searches for executables in the directories specified by the environment variable PATH. This command will print the full path of the executable(s).
-```bash
-which program_name
-```
+Searches for executables in the directories specified by the `PATH` environment variable and prints the full path.
+
+Usage:
+which program_name
+
Example:
-```bash
$ which php
/c/xampp/php/php
-```
+
### e. clear
Clears content on window.
From a3692d5e0d2c5b1f3516b9532f21fba92cf394c2 Mon Sep 17 00:00:00 2001
From: Muh Yusuf <79491810+yusuf601@users.noreply.github.com>
Date: Sun, 11 Aug 2024 21:02:44 +0700
Subject: [PATCH 6/8] Update README.md
---
README.md | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/README.md b/README.md
index 4ac4a3c..1684a4e 100644
--- a/README.md
+++ b/README.md
@@ -41,11 +41,13 @@ Usage:
export
Example:
+```bash
$ export
AWS_HOME=/Users/yourname/.aws
LANG=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LESS=-R
+```
$ echo $AWS_HOME
/Users/yourname/.aws
@@ -57,8 +59,10 @@ Usage:
whatis command_name
Example:
+```bash
$ whatis bash
bash (1) - GNU Bourne-Again SHell
+```
### c. `whereis`
Searches for executables, source files, and manual pages using a database built by the system.
@@ -67,8 +71,10 @@ Usage:
whereis name
Example:
+```bash
$ whereis php
/usr/bin/php
+```
### d. `which`
Searches for executables in the directories specified by the `PATH` environment variable and prints the full path.
@@ -77,8 +83,10 @@ Usage:
which program_name
Example:
+```bash
$ which php
/c/xampp/php/php
+```
### e. clear
From b7e70ff99b6f3a630624b4706a117ac1f0319169 Mon Sep 17 00:00:00 2001
From: Muh Yusuf <79491810+yusuf601@users.noreply.github.com>
Date: Sun, 11 Aug 2024 21:12:45 +0700
Subject: [PATCH 7/8] Update README.md
---
README.md | 40 +++++++++++++++++++++++++++++-----------
1 file changed, 29 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
index 1684a4e..67947c6 100644
--- a/README.md
+++ b/README.md
@@ -146,34 +146,52 @@ The chown command stands for "change owner", and allows you to change the owner
chown -options user:group filename
```
-### d. `cp`
-Copies a file from one location to other.
+# d. cp
+# Copies a file from one location to another.
+
+# Usage:
```bash
cp filename1 filename2
```
-Where `filename1` is the source path to the file and `filename2` is the destination path to the file.
-### e. `diff`
-Compares files, and lists their differences.
+# Where `filename1` is the source file path and `filename2` is the destination file path.
+
+
+# e. diff
+# Compares two files and lists their differences.
+
+# Usage:
```bash
diff filename1 filename2
```
-### f. `file`
-Determine file type.
+# f. file
+# Determines the file type.
+
+# Usage:
```bash
file filename
```
-Example:
+
+# Example:
```bash
$ file index.html
- index.html: HTML document, ASCII text
+index.html: HTML document, ASCII text
```
-### g. `find`
-Find files in directory
+
+
+# g. find
+# Finds files in a directory.
+
+# Usage:
```bash
find directory options pattern
```
+
+# Examples:
+```bash
+$ find . -name README.md
+$ find /home/user1 -name '*.png'
Example:
```bash
$ find . -name README.md
From 38d68fb19b6665ea5f07880e4793834714f48f0e Mon Sep 17 00:00:00 2001
From: Muh Yusuf <79491810+yusuf601@users.noreply.github.com>
Date: Sun, 11 Aug 2024 21:14:08 +0700
Subject: [PATCH 8/8] Update README.md
---
README.md | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/README.md b/README.md
index 67947c6..e84b099 100644
--- a/README.md
+++ b/README.md
@@ -147,33 +147,33 @@ chown -options user:group filename
```
# d. cp
-# Copies a file from one location to another.
+ Copies a file from one location to another.
-# Usage:
+ Usage:
```bash
cp filename1 filename2
```
-# Where `filename1` is the source file path and `filename2` is the destination file path.
+ Where `filename1` is the source file path and `filename2` is the destination file path.
# e. diff
-# Compares two files and lists their differences.
+Compares two files and lists their differences.
-# Usage:
+ Usage:
```bash
diff filename1 filename2
```
# f. file
-# Determines the file type.
+ Determines the file type.
-# Usage:
+ Usage:
```bash
file filename
```
-# Example:
+ Example:
```bash
$ file index.html
index.html: HTML document, ASCII text
@@ -181,14 +181,14 @@ index.html: HTML document, ASCII text
# g. find
-# Finds files in a directory.
+ Finds files in a directory.
-# Usage:
+ Usage:
```bash
find directory options pattern
```
-# Examples:
+ Examples:
```bash
$ find . -name README.md
$ find /home/user1 -name '*.png'