0

Is it possible to declare functions in bash like in C ?
Functions can get quite big so i don't want to define them at the beginning of the script.
For example:

#!/bin/bash

#Variable definition
myVar='Hello World'

#function declaration       <-- is this possible if yes how ?
function greeting() {}     


#main code
greeting


#function definition
function greeting() {
   echo $myVar
}
2
  • 1
    No. There is no "pure" function declaration (without the definition, as in C) in bash. Commented Feb 6, 2021 at 18:28
  • bash is interpreted, so greeting has to be defined at the point it is executed. A later definition would just replace the earlier one. Commented Feb 6, 2021 at 21:23

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.