func_name Verified current stable Not installed? Programming

Func Name / Define Function Without Keyword

Define Function Without Keyword

Defines a function in shell scripting without using the 'function' keyword.

$
Terminal
<func_name>() { <echo "Function contents here">; }

When To Use

When writing concise scripts where brevity and style are prioritized in function definition.

Pro Tip

Avoid starting function names with a number, or syntax errors will occur.

Command Builder

Tune the command before you copy it

Back to syntax
$
Generated Command
<func_name>() { <echo "Function contents here">; }

Anatomy of Output

Understanding the result

Function 'myFunc' defined without the function keyword. Definition Status

Confirms successful creation of the function.

Function body: echo 'Function contents here' Function Contents

Displays the command to execute when called.

Troubleshooting

Common pitfalls

bash: myFunc: command not found

Solution: Ensure the function is defined in the current shell session.

Unexpected token error, missing parenthesis.

Solution: Check the syntax for appropriate endings.

Function is undefined in the invoked scope.

Solution: Define the function in the global scope or ensure the scope is correct.

Command Breakdown

What each part is doing

<func_name>()
Base Command
The executable that performs this operation. Here it runs Func Name before the shell applies any redirect operators.
<func_name>
func name
The value supplied for func name.
<echo "Function contents here">
echo "Function contents here"
The value supplied for echo "Function contents here".

Alternative Approaches

Comparable commands in other tools

Alternative programming tools for the same job.