Commit 7656a10
committed
docs(Shell): explain what a .sh file is with examples
What
- Documented .sh files as shell scripts used in Linux and macOS environments.
- Key details:
- Plain text files with `.sh` extension.
- Require execution permission via chmod +x file.sh.
- Contain Unix shell commands executed sequentially.
- Commonly used for automation, system tasks, and launching applications.
- Included examples:
1. Simple hello world script:
```bash
#!/bin/bash
echo "Hello, World from Shell Script!"
```
2. Script to open IntelliJ IDEA with a project file:
```bash
#!/bin/bash
"/opt/idea-IU-2023.3/bin/idea.sh" "/home/user/Projects/JavaTutorials/src/Main.java" &
```
Why
- Provides beginners and developers with clear understanding of what .sh files are and how to use them.
- Illustrates both basic scripting (Hello World) and practical real-world usage (launching IDE with a project).
- Highlights cross-cutting importance of shell scripts in automation and software workflows.
How
- Explained role of shebang (`#!/bin/bash`) as interpreter declaration.
- Showed how commands inside .sh run in sequence.
- Explained `&` operator for running tasks in background.
- Outlined execution flow:
1. Write commands in a plain text file.
2. Save file with `.sh` extension.
3. Give execute permission with `chmod +x`.
4. Run script with `./file.sh`.
Logic
- Inputs: plain text commands.
- Outputs: execution of those commands on terminal.
- Flow:
- Shell reads file → executes commands line by line.
- If background operator `&` used, process detaches from current terminal session.
- Edge cases:
- If script lacks execute permission, error: “Permission denied.”
- Wrong shebang path leads to "No such file or directory."
- Complexity / performance: negligible; execution speed depends on commands inside.
- Concurrency / thread-safety: multiple scripts can be run concurrently in different processes.
Real-life applications
- Automating repetitive commands (compilation, deployment, backups).
- Starting servers or development tools.
- Batch operations on files and directories.
- CI/CD pipelines in software projects.
- System maintenance and monitoring tasks.
Notes
- A .sh script can run in any POSIX-compliant shell (bash, zsh, dash, etc.).
- Best practice: make scripts portable by using `#!/bin/sh` for general compatibility.
- Scripts can include logic (if-else, loops, functions) making them powerful automation tools.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent 070ddd7 commit 7656a10
1 file changed
+24
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
0 commit comments