1. Define a function
name() { ... } declares a function; the body runs each time you call name.
greet() {Typorithm · medium
Step 1 of 8 · intro card
Scripting
Define a function with name() { ... }; positional params $1, $2 hold its arguments. local scopes a variable to the function, and return sets the exit status (0–255), not a value — echo to "return" data. Call it by writing the name with args.
A bash function is declared with name() { ... } and runs its body whenever you call it. Arguments arrive as positional parameters: $1 is the first, $2 the second, and so on.
local name="$1" copies the first argument into a variable scoped to the function, so it does not leak out and clobber a same-named variable elsewhere.
return only sets the function's exit status — an integer 0–255 where 0 means success. It does not hand back a value, so to "return" data you echo it and let the caller capture the output. You invoke a function by writing its name followed by arguments, like greet "Ada".
Define with name() { ... }; args are $1, $2, ...
local scopes a variable to the function.
return sets the exit status (0–255), not a value; echo to return data.
greet() {
local name="$1"
echo "Hello, $name"
return 0
}
greet "Ada"Connect each part of the code to the concept before you type.
name() { ... } declares a function; the body runs each time you call name.
greet() {local scopes name to the function; $1 is the first argument passed to it.
local name="$1"echo writes to stdout — the way a function "returns" data for a caller to capture.
echo "Hello, $name"return sets the function's exit status (0–255); 0 means success, not a returned value.
return 0Calling is just the function name followed by arguments, here "Ada" as $1.
greet "Ada"Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.