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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access