mirror of
https://github.com/TrudeEH/web.git
synced 2025-12-06 00:13:36 +00:00
Use dash for scripts instead of bash; Fix typo
This commit is contained in:
10
content/.obsidian/workspace.json
vendored
10
content/.obsidian/workspace.json
vendored
@@ -14,12 +14,12 @@
|
|||||||
"state": {
|
"state": {
|
||||||
"type": "markdown",
|
"type": "markdown",
|
||||||
"state": {
|
"state": {
|
||||||
"file": "drafts/bash.md",
|
"file": "notes/firewall.md",
|
||||||
"mode": "source",
|
"mode": "source",
|
||||||
"source": false
|
"source": false
|
||||||
},
|
},
|
||||||
"icon": "lucide-file",
|
"icon": "lucide-file",
|
||||||
"title": "bash"
|
"title": "firewall"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -218,13 +218,14 @@
|
|||||||
},
|
},
|
||||||
"active": "b1ce9fc55dcb67b6",
|
"active": "b1ce9fc55dcb67b6",
|
||||||
"lastOpenFiles": [
|
"lastOpenFiles": [
|
||||||
"Pasted image 20250422121610.png",
|
"notes/firewall.md",
|
||||||
|
"drafts/bash.md",
|
||||||
"notes/linux/index.md",
|
"notes/linux/index.md",
|
||||||
|
"Pasted image 20250422121610.png",
|
||||||
"Pasted image 20250422122034.png",
|
"Pasted image 20250422122034.png",
|
||||||
"notes/index/index.md",
|
"notes/index/index.md",
|
||||||
"Pasted image 20250422123058.png",
|
"Pasted image 20250422123058.png",
|
||||||
"Pasted image 20250422122140.png",
|
"Pasted image 20250422122140.png",
|
||||||
"drafts/bash.md",
|
|
||||||
"notes/c-language.md",
|
"notes/c-language.md",
|
||||||
"drafts/gobject.md",
|
"drafts/gobject.md",
|
||||||
"drafts/lua.md",
|
"drafts/lua.md",
|
||||||
@@ -235,7 +236,6 @@
|
|||||||
"notes/gdb.md",
|
"notes/gdb.md",
|
||||||
"notes/flask.md",
|
"notes/flask.md",
|
||||||
"notes/encryption.md",
|
"notes/encryption.md",
|
||||||
"notes/firewall.md",
|
|
||||||
"notes/compiling.md",
|
"notes/compiling.md",
|
||||||
"notes/c-snippets.md",
|
"notes/c-snippets.md",
|
||||||
"search.md",
|
"search.md",
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ tags:
|
|||||||
author: TrudeEH
|
author: TrudeEH
|
||||||
showToc: true
|
showToc: true
|
||||||
---
|
---
|
||||||
A firewall monitors and controls all incoming and outgoing network traffic, and can be implemented in the hardware or software level.
|
A firewall monitors and controls all incoming and outgoing network traffic, and can be implemented at the hardware or software level.
|
||||||
|
|
||||||
## See All Open Ports
|
## See All Open Ports
|
||||||
|
|
||||||
|
|||||||
@@ -206,11 +206,11 @@ The GPU still has a device file, which is used by the Kernel's DRM and Mesa, but
|
|||||||
|
|
||||||
## Shell (`bash`)
|
## Shell (`bash`)
|
||||||
|
|
||||||
The kernel by itself isn't intractable, so a shell is needed for the user to be able to execute programs and run commands. Bash is not only a prompt, but also an interpreter for its own programming language, which can be used to write scripts and automate tasks.
|
The kernel by itself isn't intractable, so a shell is needed for the user to be able to execute programs and run commands. `bash` is not only a prompt, but also an interpreter for its own programming language, which can be used to write scripts and automate tasks.
|
||||||
|
|
||||||
### Commands
|
### Commands
|
||||||
|
|
||||||
Bash performs actions through commands. A shell command consists of the command itself, followed by its arguments.
|
`bash` performs actions through commands. A shell command consists of the command itself, followed by its arguments.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
command "arg1" "arg2"
|
command "arg1" "arg2"
|
||||||
@@ -218,14 +218,18 @@ command "arg1" "arg2"
|
|||||||
|
|
||||||
If the first word of a command is a reserved word, bash handles the command, otherwise, it searches for an executable on the system's `$PATH`, a list of directories where a binary could be located.
|
If the first word of a command is a reserved word, bash handles the command, otherwise, it searches for an executable on the system's `$PATH`, a list of directories where a binary could be located.
|
||||||
|
|
||||||
### Bash Scripts
|
### Shell Scripts
|
||||||
|
|
||||||
|
While `bash` is typically used as the login shell, it is slow for script execution. For this reason, many distributions (such as Debian) use `dash` to run `sh` scripts (symlink `/bin/sh` to `/bin/dash`), which is a faster alternative to `bash`, designed specifically to execute scripts and to be strictly POSIX compliant.
|
||||||
|
|
||||||
|
When writing scripts, it's a good practice to follow the POSIX standard, to make them compatible with most shells, older systems, and different distributions, while taking advantage of `dash`'s faster performance. Keep in mind that `dash` is not `bash` compatible, and some `bash` commands might not work on `dash`.
|
||||||
|
|
||||||
Example `script.sh`:
|
Example `script.sh`:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
#! /bin/bash
|
#! /bin/sh
|
||||||
|
|
||||||
echo "Bash Script"
|
echo "Shell Script"
|
||||||
```
|
```
|
||||||
|
|
||||||
Execute the script:
|
Execute the script:
|
||||||
@@ -235,15 +239,15 @@ chmod u+x script.sh # Give the script execution permission (to its owner)
|
|||||||
./script.sh # Run the script
|
./script.sh # Run the script
|
||||||
```
|
```
|
||||||
|
|
||||||
|
After writing a script, use `shellcheck` to check for issues.
|
||||||
|
|
||||||
### Learning
|
### Learning
|
||||||
|
|
||||||
There are some commands available to search for documentation:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
tldr command # Examples of how to use the command (external tool)
|
tldr command # Examples of how to use the command (external tool)
|
||||||
help command # Short documentation for the command
|
help command # Short documentation for the command
|
||||||
man command # Full documentation for the command
|
man command # Full documentation for the command
|
||||||
man bash # Bash documentation; Includes most built-in commands
|
man dash # Dash documentation; Includes most built-in commands
|
||||||
```
|
```
|
||||||
|
|
||||||
> To get started, use `help` by itself, which provides a list of the built-in commands available in bash.
|
> To get started, use `help` by itself, which provides a list of the built-in commands available in bash.
|
||||||
@@ -253,6 +257,8 @@ For example, suppose you want to learn how to write an `if` statement in `bash`:
|
|||||||

|

|
||||||
As suggested by `tldr`, to see all possible conditions, use the `man test` command.
|
As suggested by `tldr`, to see all possible conditions, use the `man test` command.
|
||||||
|
|
||||||
|
> If you are writing scripts using `dash`, it's recommended to read the `dash` manual instead: `man dash`. The `if [[ ]]` syntax is exclusive to `bash`, for example, and should be replaced with `if [ ]` to use with `dash`.
|
||||||
|
|
||||||
### Compiling
|
### Compiling
|
||||||
|
|
||||||
Dependencies:
|
Dependencies:
|
||||||
@@ -286,6 +292,8 @@ sudo apt install ../bash*.deb
|
|||||||
|
|
||||||
Bash includes a set of *builtins*: Command-line utilities that come within bash itself. However, these are very limited, and to actually make the computer useful, more programs are needed.
|
Bash includes a set of *builtins*: Command-line utilities that come within bash itself. However, these are very limited, and to actually make the computer useful, more programs are needed.
|
||||||
|
|
||||||
|
> To learn more about a program, use: `man program_name`.
|
||||||
|
|
||||||
### Coreutils
|
### Coreutils
|
||||||
|
|
||||||
*Coreutils* are a collection of small command-line utilities, which are essential for text, file and shell manipulation.
|
*Coreutils* are a collection of small command-line utilities, which are essential for text, file and shell manipulation.
|
||||||
|
|||||||
Reference in New Issue
Block a user