-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial.sh
More file actions
39 lines (32 loc) · 870 Bytes
/
tutorial.sh
File metadata and controls
39 lines (32 loc) · 870 Bytes
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
#!/bin/bash
# VARIABLES
greeting="Hello"
user=$(whoami) # Get the current user
today=$(date +"%A, %B %d, %Y") # Get the current date
# FUNCTION
function say_hello {
echo "$greeting, $user! Today is $today."
}
# CONDITIONAL STATEMENT
function check_file {
if [ -f "$1" ]; then # uses $1 as a positional variable
echo "✅ File '$1' exists."
else
echo "❌ File '$1' does not exist."
fi
}
# LOOP
function list_files {
echo "📂 Listing files in the current directory:"
for file in *; do
echo " - $file"
done
}
# USER INPUT
echo "🔹 Enter a filename to check:"
read filename # Store user input
# FUNCTION CALLS
say_hello # Call the greeting function
check_file "$filename" # Check if the file exists and states the argument
list_files # List files in the directory
echo "🎉 Script execution completed!"