Skip to content

Commit 7656a10

Browse files
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

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
What is a .sh File?
2+
3+
A .sh file is a shell script used in Linux and macOS.
4+
It contains a series of Unix commands executed by the shell (bash, zsh, etc.).
5+
6+
Key Features of a .sh File:
7+
- Plain text file with .sh extension.
8+
- Must be given execute permission (chmod +x file.sh).
9+
- Runs commands in sequence inside the terminal.
10+
- Used for automation, system tasks, software builds, etc.
11+
12+
Example 1: Simple Hello World
13+
#!/bin/bash
14+
echo "Hello, World from Shell Script!"
15+
16+
Example 2: Open IntelliJ IDEA on Linux
17+
#!/bin/bash
18+
"/opt/idea-IU-2023.3/bin/idea.sh" "/home/user/Projects/JavaTutorials/src/Main.java" &
19+
20+
How It Works:
21+
- #!/bin/bash specifies the interpreter.
22+
- Path "/opt/idea-IU-2023.3/bin/idea.sh" is IntelliJ startup script.
23+
- Second path points to the Java file to open.
24+
- & runs the program in the background.

0 commit comments

Comments
 (0)