Skip to content

Commit e953b40

Browse files
Merge pull request #25 from wooddang-gachon/Add-basic-bash-syntax-examples
Add basic bash syntax examples Closes #15
2 parents 0dd264c + 519b515 commit e953b40

6 files changed

Lines changed: 162 additions & 0 deletions

File tree

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Basic Shell Scripting Examples
2+
3+
This folder contains **basic Bash shell scripting examples** for beginners.
4+
Each script demonstrates a core concept commonly used in shell scripting.
5+
6+
---
7+
8+
## Prerequisites
9+
10+
* Linux / macOS terminal (or Git Bash / WSL on Windows)
11+
* Bash shell
12+
* Basic terminal knowledge (`cd`, `ls`)
13+
14+
Make scripts executable (optional):
15+
16+
```bash
17+
chmod +x *.sh
18+
```
19+
20+
---
21+
22+
## Scripts Overview
23+
24+
### 1️⃣ `variables.sh`
25+
26+
**What it demonstrates**
27+
28+
* How to declare and use variables in Bash
29+
30+
**How to run**
31+
32+
```bash
33+
bash variables.sh
34+
```
35+
36+
**What you should learn**
37+
38+
* Variable assignment syntax
39+
* How to reference variables using `$`
40+
* Difference between strings and variables
41+
42+
---
43+
44+
### 2️⃣ `echo.sh`
45+
46+
**What it demonstrates**
47+
48+
* Printing output to the terminal using `echo`
49+
50+
**How to run**
51+
52+
```bash
53+
bash echo.sh
54+
```
55+
56+
**What you should learn**
57+
58+
* How to display text
59+
* How to print variables
60+
* Basic output formatting
61+
62+
---
63+
64+
### 3️⃣ `if_else.sh`
65+
66+
**What it demonstrates**
67+
68+
* Conditional logic using `if`, `else`
69+
70+
**How to run**
71+
72+
```bash
73+
bash if_else.sh
74+
```
75+
76+
**What you should learn**
77+
78+
* How conditions work in Bash
79+
* Using comparison operators
80+
* Controlling script flow based on conditions
81+
82+
---
83+
84+
### 4️⃣ `loops.sh`
85+
86+
**What it demonstrates**
87+
88+
* Looping with `for` (and/or `while`)
89+
90+
**How to run**
91+
92+
```bash
93+
bash loops.sh
94+
```
95+
96+
**What you should learn**
97+
98+
* Repeating commands using loops
99+
* Iterating over values
100+
* Automating repetitive tasks
101+
102+
---
103+
104+
### 5️⃣ `hello.sh`
105+
106+
**What it demonstrates**
107+
108+
* A simple end-to-end Bash script
109+
110+
**How to run**
111+
112+
```bash
113+
bash hello.sh
114+
```
115+
116+
**What you should learn**
117+
118+
* Basic script structure
119+
* Using `echo`
120+
* Running a shell script from the terminal
121+
122+
---
123+
124+
## Notes
125+
126+
* These examples are intentionally simple for learning purposes.
127+
* Try editing the scripts and re-running them to better understand how Bash works.
128+
129+
Happy scripting! 🚀
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
echo "Hello, World"
3+
echo "My name is $name"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
echo "hello"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
name="Wooddang"
3+
4+
if [ "$name" = "Wooddang" ]; then
5+
echo "Welcome, Wooddang!"
6+
else
7+
echo "Access denied"
8+
fi
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
#!/bin/bash
3+
for i in 1 2 3 4 5
4+
do
5+
echo "Number: $i"
6+
done
7+
8+
count=1
9+
10+
while [ $count -le 3 ]
11+
do
12+
echo "Count is $count"
13+
count=$((count + 1))
14+
done
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
name="Wooddang"
3+
age=30
4+
5+
echo $name
6+
echo $age

0 commit comments

Comments
 (0)