Function scope

Functions defined during a bash session are only available in that session. You cannot define a function on the command line, and then expect to have it available in a Bash script you execute, or in another user's bash session. You would need to include the function definition in the script, and have the other user load your function first.

Functions that use curly brackets, {...}, for the function body operate in the current process of the shell. This allows you to have functions that can change your current working directory, such as cd shortcuts, to view and set variables for the current active shell, or to set shell runtime options, such as -x.

This means that variable assignments aren't local to functions; they're visible ...

Get Bash Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.