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
}
int3g3r
  • 15
  • 4
  • 1
    No. There is no "pure" function declaration (without the definition, as in `C`) in `bash`. – M. Nejat Aydin Feb 06 '21 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. – stark Feb 06 '21 at 21:23

0 Answers0