Does bash function return?

Does bash function return?

Although bash has a return statement, the only thing you can specify with it is the function’s status, which is a numeric value like the value specified in an exit statement. If a function does not contain a return statement, its status is set based on the status of the last statement executed in the function.

How do I return a bash script?

To end a shell script and set its exit status, use the exit command. Give exit the exit status that your script should have. If it has no explicit status, it will exit with the status of the last command run.

What is return in bash?

Function Return A bash function can return a value via its exit status after execution. By default, a function returns the exit code from the last executed command inside the function. Syntax: return [n] where n is a number. If n is not supplied, then it will return the exit code of the last command run.

Where are bash functions stored?

Typically bash functions are permanently stored in a bash start-up script.

  1. System-wide start-up scripts: /etc/profile for login shells, and /etc/bashrc for interactive shells.
  2. User define start-up scripts: ~/.
  3. More information on interactive/login shells can be found in the bash man page in the INVOCATION section.

When to use return instead of exit in Bash?

Using return instead of exit will allow you to still launch your script using . ./

Is it possible to return value from BASH script?

It’s not possible to return a value from a bash script. If you echo the result, the calling process can grab it. A numeric can be returned with exit but that’s not recommended as this is represents a status code (and also some codes are reserved – so ‘should’ not be used). – wmorrison365 Nov 8 ’17 at 10:17

What happens if I run a bash script?

If what you are showing is only a portion of a larger script containing a call to the installZook function, then the function can still only cause the terminal to terminate if the script is sourced, but not through being run as an ordinary shell script. exit terminates the current shell session.

Can a Bash function return a value to the caller?

Bash functions, unlike functions in most programming languages do not allow you to return a value to the caller. When a bash function ends its return value is its status: zero for success, non-zero for failure.