Having problems calling function within bash script -


i've been working on our intro scripting assignment, , having issues calling functions within script. in second portion of assignment, , testing make sure have (hopefully) going work. have gathered directories, , ask yes or no question. when 'y', wrote little function call, , when 'n' have function, both simple echoes. issue?

part_two(){     answer=""     value in "$@";do       echo "$value"       while [ "$answer" != "y" -a "$answer" != "n" ]                echo -n "would save results file? (y/n): "         read answer       done       if [ "$answer" = "n" ]                    part_six       elif [ "$answer" = "y" ]                    part_five       fi      done }  part_two $@  part_five(){     echo -n "working yes"; }  part_six(){     echo -n "working no"; } 

any appreciated, always.

much in c function must defined before it's used. in code snippet calling part_two (which calling part_five , part_six) before declaring 2 functions.

have tried moving definitions start of script?

edit:

in cases, best way deal in bash define functions @ start of script before executing actual commands. order of definitions not matter - shell looks function when it's use - there no dependency issues etc. may have think about.

edit 2:

there are cases may not able define function @ start of script. common case when use conditional constructs dynamically select or modify declaration of function e..g.:

if [[ "$1" = 0 ]];     function show() {         echo 0     } else     function show() {         echo not-zero     } fi 

in these cases you have make sure each function call happens after function (and others calls) declared.

edit 3:

in bash function declaration function foo() { ... } block define implementation - , yes, function keyword not strictly necessary. there no function prototypes in c - not make sense anyway because shell scripts parsed executed. newer bash version read script @ once, check syntax errors , not logical errors such one.

btw official term "function declaration", bash info page uses "declaration" , "definition" interchangeably.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -