Introduction
Functions let you group commands together to reuse them easily and keep your script organized.
function_name() {
commands
}
# or
function function_name() {
commands
}greet() {
echo "Hello, friend!"
}function say_goodbye() {
echo "Goodbye!"
}print_date() {
date
}#!/bin/bash say_hello() { echo "Hello, welcome to the script!" } say_hello
greet in bash?name() { commands; } or function name { commands; }.function name() { commands; } or name() { commands; }.say_hello() {
echo "Hello, $1!"
}
say_hello Alicesay_hello takes one argument and prints it using $1.say_hello Alice replaces $1 with "Alice", so output is "Hello, Alice!".function greet {
echo "Hi"
}function name() { commands; } or function name { commands; }. Parentheses after the name are optional.function greet { echo "Hi"; } is valid syntax.sum that takes two numbers and prints their sum. Which function definition correctly does this?$(()) inside echo.$(($1 + $2)). Options A and B print strings with plus sign, not sum. sum() { echo $1 $2; } prints numbers without adding.Pass the test and this pattern moves unknown