'Calling a batch function from a called batch file

I have a set of many batch files which are called from one another. For example.

File1.batch --> CALL file2.bat |--> CALL file3.bat
                               |--> CALL file4.bat --> CALL file5.bat
                               |--> CALL file6.bat

Now there is a common set of instruction that I need to execute multiple times in all the bat files. in other words, I want to create a function and use in all file multiple times..

I think I can create a function like this

:COMMONCODE
  ECHO "these are my common steps %~1"
  EXIT /B 0

But If I have 2 issues....

  1. If put these lines in File1.bat somewhere at the top before calling any other batch file my other batch file are not called. I think it just see EXIT /B 0 and stop there

  2. the %~1 is taking the File1.bat parameter as instead and printing it.

I think batch file is executed line by line... What I'm designing as a function is actually just a label. which if encountered before the main code will be executed as is... But is there a way to define a proper function, which will not be executed until called



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source