If I can understand your question: you want a method that allows a batch script to determine if it was called via a call
command from another batch script. Next 33939966test.bat
script shows possible approach: force usage with mandatory parameter "^%%%%"
as follows:
@ECHO OFF >NUL
if "%~1" == "" goto :USAGE
if "%~1" == "^^%%" echo call from another script %* & goto :GOOD
if "%~1" == "^%%%%" echo from another script %* & goto :USAGE
if "%~1" == "^^%%%%%%%%" echo call from command line %* & goto :USAGE
if "%~1" == "^%%%%%%%%" echo from command line %* & goto :USAGE
echo(wrong 1st parameter %%*=%*
goto :USAGE
:GOOD
echo(
rem echo original %%*=%*
shift /1
rem echo shifted %%*=%*
:: Note that `shift` does not affect %*
:::::::::::::::::::::::::::::::::::::::
:: Useful code begins here
goto :eof
:USAGE
echo USAGE: CALL %~nx0 "^%%%%%%%%" [parameters]
echo(
rem the 1st parameter must be:
rem "CARET followed by four PERCENT SIGNS" including all " DOUBLE QUOTES
goto :eof
Output from command line:
==> rem cmd copy&paste start
==> ECHO OFF >NUL
33939966test.bat "C&D pay 21 % VAT" "^=caret" %OS% %%OS%%
wrong 1st parameter %*="C&D pay 21 % VAT" "^=caret" Windows_NT %Windows_NT%
USAGE: CALL 33939966test.bat "^%%%%" [parameters]
call 33939966test.bat "^%%%%" "C&D pay 21 % VAT" "^=caret" %OS% %%OS%%
call from command line "^^%%%%" "C&D pay 21 % VAT" "^^=caret" Windows_NT %Windows_NT%
USAGE: CALL 33939966test.bat "^%%%%" [parameters]
33939966test.bat "^%%%%" "C&D pay 21 % VAT" "^=caret" %OS% %%OS%%
from command line "^%%%%" "C&D pay 21 % VAT" "^=caret" Windows_NT %Windows_NT%
USAGE: CALL 33939966test.bat "^%%%%" [parameters]
ECHO ON >NUL
==> rem cmd copy&paste end
Output from a caller:
==> 33939966myCaller.bat
==> call 33939966test.bat "C&D pay 21 %% VAT" "^=caret" Windows_NT %OS%
wrong 1st parameter %*="C&D pay 21 % VAT" "^^=caret" Windows_NT Windows_NT
USAGE: CALL 33939966test.bat "^%%%%" [parameters]
==> call 33939966test.bat "^%%" "C&D pay 21 %% VAT" "^=caret" Windows_NT %OS%
call from another script "^^%" "C&D pay 21 % VAT" "^^=caret" Windows_NT Windows_NT
==> 33939966test.bat "^%%" "C&D pay 21 % VAT" "^=caret" Windows_NT %OS%
from another script "^%%" "C&D pay 21 % VAT" "^=caret" Windows_NT %OS%
USAGE: CALL 33939966test.bat "^%%%%" [parameters]
where the 33939966myCaller.bat
reads as follows (copy&paste part included):
@ECHO ON
call 33939966test.bat "C&D pay 21 %%%% VAT" "^=caret" %OS% %%OS%%
@ECHO ON
call 33939966test.bat "^%%%%" "C&D pay 21 %%%% VAT" "^=caret" %OS% %%OS%%
@ECHO ON
33939966test.bat "^%%%%" "C&D pay 21 %% VAT" "^=caret" %OS% %%OS%%
@ECHO OFF
goto :eof
rem cmd copy&paste start
ECHO OFF >NUL
33939966test.bat "C&D pay 21 % VAT" "^=caret" %OS% %%OS%%
call 33939966test.bat "^%%%%" "C&D pay 21 % VAT" "^=caret" %OS% %%OS%%
33939966test.bat "^%%%%" "C&D pay 21 % VAT" "^=caret" %OS% %%OS%%
ECHO ON >NUL
rem cmd copy&paste end
Note that above approach is not bullet-proof as we could imagine false positive from command line:
==> 33939966test.bat "^^%" "C&D pay 21 % VAT" "^=caret" %OS% %%OS%%
call from another script "^^%" "C&D pay 21 % VAT" "^=caret" Windows_NT %Windows_NT%
Perhaps combining with (goto)
technique could help?