Article 4WFQT Functions in a bash script question...

Functions in a bash script question...

by
taylorkh
from LinuxQuestions.org on (#4WFQT)
Based upon some excellent advice from members of this forum I am redesigning a script which has gotten a little to complicated. Most of the code will be broken into functions and only the main flow control logic will be in the "main" part of the script. It is already looking much more manageable. However...

I have been playing with some simple scripts and functions to get my head wrapped around how bash handles functions. From what I am seeing I must define my function FIRST and then call the function. I will have a situation where function3 may need to call function5. Does this mean I must define function3 before funtion3 and all functions before I code the control loops and if statements? That seems contrary to "top down" programming. Sort of inside out programming :)

In other languages and environments I could place functions, especially utility type functions, in a separate file and then "assimilate" that file into the program at run time in an interpreted environment or at compile/pseudo-compile time. I suspect there is a way to handle this in bash. If I source the file containing the functions from within the main script, will all the functions be available in the main script?

TIA,

Kenlatest?d=yIl2AUoC8zA latest?i=AfTSyyzCIKg:16pBspIvzyA:F7zBnMy latest?i=AfTSyyzCIKg:16pBspIvzyA:V_sGLiP latest?d=qj6IDK7rITs latest?i=AfTSyyzCIKg:16pBspIvzyA:gIN9vFwAfTSyyzCIKg
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments