Text Practice Mode
Bash Script to practice typing
created Dec 6th, 08:00 by Code2Roj
1
99 words
16 completed
5
Rating visible after 3 or more votes
00:00
#!/bin/bash
# Declare a variable
greeting="Welcome to Bash scripting!"
# Function to print the greeting
print_greeting() {
echo "$greeting"
}
# Function to demonstrate error handling
check_file() {
local file="$1"
if [[ -f "$file" ]]; then
echo "File '$file' exists."
else
echo "Error: File '$file' does not exist!" >&2
return 1
fi
}
# Demonstrate a for loop
print_numbers() {
echo "Printing numbers from 1 to 5:"
for i in {1..5}; do
echo "Number: $i"
done
}
# Main script logic
print_greeting
check_file "example.txt" || echo "Proceeding despite missing file."
print_numbers
# Exit with success status
exit 0
# Declare a variable
greeting="Welcome to Bash scripting!"
# Function to print the greeting
print_greeting() {
echo "$greeting"
}
# Function to demonstrate error handling
check_file() {
local file="$1"
if [[ -f "$file" ]]; then
echo "File '$file' exists."
else
echo "Error: File '$file' does not exist!" >&2
return 1
fi
}
# Demonstrate a for loop
print_numbers() {
echo "Printing numbers from 1 to 5:"
for i in {1..5}; do
echo "Number: $i"
done
}
# Main script logic
print_greeting
check_file "example.txt" || echo "Proceeding despite missing file."
print_numbers
# Exit with success status
exit 0
saving score / loading statistics ...