mirror of
https://github.com/ebrandi/FDD-book.git
synced 2026-12-06 00:23:30 +00:00
Organize companion code and materials by book part: part-01/ Foundations part-02/ Kernel & driver fundamentals part-03/ Character & block devices part-04/ Networking & storage part-05/ Buses & advanced topics part-06/ Debugging & performance part-07/ Real-world drivers appendices/ Supplementary material README.md Overview and build instructions
40 lines
870 B
Bash
40 lines
870 B
Bash
#!/bin/sh
|
|
# functions.sh - Demonstrates using functions and command-line arguments in a shell script.
|
|
#
|
|
# Usage:
|
|
# ./functions.sh NUM1 NUM2
|
|
# Example:
|
|
# ./functions.sh 5 7
|
|
# This will output: "[INFO] 5 + 7 = 12"
|
|
|
|
# A simple function to print informational messages
|
|
say() {
|
|
# "$1" represents the first argument passed to the function
|
|
echo "[INFO] $1"
|
|
}
|
|
|
|
# A function to sum two integers
|
|
sum() {
|
|
# "$1" and "$2" are the first and second arguments
|
|
local a="$1"
|
|
local b="$2"
|
|
|
|
# Perform arithmetic expansion to add them
|
|
echo $((a + b))
|
|
}
|
|
|
|
# --- Main script execution starts here ---
|
|
|
|
# Make sure the user provided two arguments
|
|
if [ $# -ne 2 ]; then
|
|
echo "Usage: $0 NUM1 NUM2"
|
|
exit 1
|
|
fi
|
|
|
|
say "Beginning work"
|
|
|
|
# Call the sum() function with the provided arguments
|
|
result="$(sum "$1" "$2")"
|
|
|
|
# Print the result in a nice format
|
|
say "$1 + $2 = $result"
|