blob: 56964567fb459e39fab6a42c48c5a7204295c9bb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#!/bin/bash
# A simple bash script demo
APP_NAME="MyShellApp"
VERSION="1.0.0"
echo "Starting $APP_NAME version $VERSION..."
# Check if a directory exists
if [ -d "/tmp" ]; then
echo "/tmp directory exists."
else
echo "/tmp directory does not exist, creating it..."
mkdir /tmp
fi
# Loop through arguments
echo "Arguments provided:"
for arg in "$@"; do
echo "- $arg"
done
# Function definition
greet() {
local name=$1
echo "Hello, $name!"
}
# Call function
greet "User"
# While loop
count=0
while [ $count -lt 5 ]; do
echo "Count: $count"
((count++))
done
# Case statement
case "$1" in
start)
echo "Starting service..."
;;
stop)
echo "Stopping service..."
;;
restart)
echo "Restarting service..."
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
echo "Done."
|