A function definition is a command. When a function definition is run, I thought that the function body would be kept intact,  as if the function body  is single quoted.I knew I was wrong, when I understood the following from the Bash manual  in G-Mans answerto my Alias and functions question:Aliases are expanded when a function definition is read, not when the function is executed, .So alias expansion is performed in the function body, while parameter expansion is not, as shown by the following example:$ alias myalias=cat$ echo $var3$ myfunc() { myalias myfile; echo $var; }$ declare -fp myfuncmyfunc () {     cat myfile;    echo $var}Similarly, a call to a function is also a command.aliases defined in a function are not available until after that function is executed.so alias definition is executed only when executing, i.e., calling the function, not when running the function definition.alias expansions and alias definition execution are just two of the shell operations listed below.        My questions are:What shell operations  are performed inside the function body, andwhat operations are not performed,when running a function definition?when calling a function, i.e., executing a function?Are there any shell operations which are performed during bothrunning the definition of a function and calling the function?Or do running the definition of a function and calling the functionperform non-overlapping sets of shell operations?The possible operations are listed in the following quote from the Bash manual:3.1.1 Shell OperationThe following is a brief description of the shells operation when it reads and executes a command. Basically, the  shell does the following:Reads its input from a file (see Section 3.8 [Shell Scripts], page 39), from a string supplied as an argument to the -c invocation option  (see Section 6.1 [Invoking Bash], page 80), or from the users  terminal.Breaks the input into words and operators, obeying the quoting rules described in Section 3.1.2 [Quoting], page 6. These tokens are  separated by metacharacters. Alias expansion is performed by this step  (see Section 6.6 [Aliases], page 88).Parses the tokens into simple and compound commands (see Section 3.2 [Shell Commands], page 8).Performs the various shell expansions (see Section 3.5 [Shell Expansions], page 21), breaking the expanded tokens into lists of  filenames (see Section 3.5.8 [Filename Expansion], page 30) and  commands and arguments.Performs any necessary redirections (see Section 3.6 [Redirections], page 31) and removes the redirection operators and  their operands from the argument list.Executes the command (see Section 3.7 [Executing Commands], page 35).Optionally waits for the command to complete and collects its exit status (see Section 3.7.5 [Exit Status], page 38).
Which of the following shell operations are performed inside the function body when running a function definition and when calling a function?
bash;function
<rant>running a function definition and running the definition of a functionare not common idioms.Iexpect that most people would refer to thatsimply as defining a function.OK, that phrase might be interpreted to refer toconceptually specifying the characteristics and interfaces(parameters and other inputs, processing, and outputs) of a function(this is an activity performed by a person, or a group of people)choosing the implementation of a function;i.e., what commands to use in the function body.This is an activity performed by a person, or a group of people,possibly using paper, whiteboards, and/or blackboards.typing the implementation of a functioninto a text editor or directly into an interactive shell(this, of course, is also an activity performed by a person,or possibly a group of people,or possibly a very intelligent and dexterous cat, dog or monkey)If you fear confusion with the above,you might be better served by phrases like reading a function definitionand processing the definition of a function.You say, A function definition is a command.Its not clear what a claim like that even means its a matter of semantics  but, at the semantic level, its debatable.Section3.2 of the Bash manual (Shell Commands)lists six kinds of shell commands:Simple Commands, Pipelines, Lists, Compound Commands, Coprocesses,and GNU Parallel.Function definitions dont fit well into any of those categories.</rant>Getting to your question, and looking at the seven steps/operations,Reading input obviously has to happenbefore anything else can happen.Its, again, a matter of semantics you could say that reading input from a file or other stream text sourceis part of reading a function definitionor that it is a prerequisite/prelude toprocessing the definition of a function.Breaking the input into words and operatorsis clearly part of processing the definition of a function.Breaking the input into tokens is, of course,a prerequisite/prelude to parsing the tokens (step3, below).The manual says, Alias expansion is performed by this step,and you show in the question that you know thatalias expansion happens when the function definition is read.Parsing the tokens.This must at least startduring the processing the definition of a function phasefor the shell to realize that it is looking at a function definitionand not a simple command.Beyond that, we can do this simple experiment:type either of the following into a shell:myfunc1() {                     myfunc2() {    <               or              ;}                               }It will fail with a syntax errorbefore you get a chance to type the }.(> and & produce the same effect.)So clearly this step is part of processing the definition of the function.Performing the various shell expansionsis part of calling the function.You show in the question that you know thatparameter expansion does not happenwhen the function definition is read.Its equally trivial to demonstrate that pathname/filename expansiondoes not happen when the function definition is read.In your example, change echo$var(which should be echo$var, but thats another matter) to echo*.If you look at the function definition,youll see that it still says echo* and has not been expanded.Change directory (cd) and/or create file(s)and/or delete file(s) and/or rename file(s),and then call (execute) the function.Youll see that it outputs the current list of files1in the current directory,and doesnt reflect the contents of the directorywhere/when you defined the function.Performing redirections is part of calling the function.This is also trivial to verify.In your example, change echo$var to echohello>myfile.If you look at the function definition,youll see that it still says >myfile.Check the directory,and youll see that myfile has not been created (yet).Executing the command  do you really need to ask?Waiting for the command to complete cant possibly happenuntil the command has been executed (step6),so this obviously is performed only when calling the function.In other words, exactly what @ilkkachu said.The one exceptional special case I can think ofis that steps2 and3 (lexical analysis and parsing) occur (again)when executing a function if the function contains eval statements but I believe that thats outside the scopeof what your question is really asking.____________1 excluding hidden (dot-) files,unless you have said shopt-sdotglob