Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

batch script print the command that would be executed rather than executing

Is it possible to set a cmd.exe shell / batch file to print what would be executed but not actually execute it?

For example, given a batch file that takes some arguments, based on those arguments selects some other batch files to run, those batch files execute some commands, may or may not call other files/commands etc.

I would like to be able to run the top level batch file with all possible combinations of it's input arguments and capture what each arg combination would execute - without actually trying to execute it.

e.g. conceptually would want to be able to produce something like:

mybatchfile.bat 1 2 3 > mybatchfile_1_2_3.bat

mybatchfile.bat 99 3 42 > mybatchfile_99_3_42.bat

where mybatchfile_99_3_42.bat is the list of everything that WOULD be executed when running mybatchfile.bat 99 3 42 (NOT the output of executing those commands)

If this can't be done solely using cmd.exe is there someway to achieve this by running the batch script in cygwin bash shell

like image 861
hanlonj Avatar asked Nov 19 '25 03:11

hanlonj


2 Answers

In bash we would use something like -x to print out all possible commands without executing them. how to make bash scripts print out every command before executing The problem is that to my knowledge there's no exact equivalent command for Batch Scripts. I would suggest you try placing:

@echo on

at the beginning of your script and:

@echo off

at the end of your script, that's the best starting place.

like image 170
secumind Avatar answered Nov 21 '25 19:11

secumind


If you never want the batch file to actually execute the commands, you can insert echo before each command. It's not a perfect solution by any means, but it may be a work-around for fairly simple scripts.

like image 25
Adam Liss Avatar answered Nov 21 '25 18:11

Adam Liss



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!