Update:
I am working on a modular shell script that calls usage() at a different subprocess level. script sample.sh has a structure that looks like below:
sample.sh ├─ ... ├─ usage() ├─ awk ├─ usage() ├─ ...
usage() displays a summary of how to use the script (e.g. available arguments and descriptions). When run for the first time, usage() displayed at the beginning of the script. Examples of other conditions for calling usage() :
I would like to call the identical usage() function, from the shell and its direct child process, awk .
The original question:
The usage() sample.sh prints the print instruction as desired.
$cat sample.sh #!/bin/sh awk ' BEGIN { usage() } function usage() { print "function inside of awk" } ' $./sample.sh function inside of awk
To take usage() out of awk and put it as a local function in sample.sh~ , I tried:
$cat sample.sh~ #!/bin/sh usage() { print "function outside of awk" } awk ' BEGIN { usage() } ' $./sample.sh~ awk: calling undefined function usage source line number 3
As we can see, we get the error message "undefined function use" in sample.sh~ . How to improve it?
source share