23

Is there a generic way of running a bash script and seeing the commands that result, but not actually run the commands - i.e. a "dry run"/simulator of sorts?

I have a database install script (actually "make install" after running ./configure and make) that I wish to run, but it's installing all sorts of stuff that I don't want.

So I'd like a way to see exactly what it's going to do before I run it for real - maybe even run the commands by hand instead.

Is there any utility that can perform such a task (or anything related/similar)?

4
  • I think 'set -n' does something like that. Try adding -x as well. Commented Apr 11, 2016 at 21:58
  • How do I pipe "make install" to set -n? Commented Apr 11, 2016 at 22:23
  • bash -n make install, but from man bash: "An interactive shell may ignore this option." Commented Apr 11, 2016 at 22:35
  • There is no dryrun option in bash. See also here stackoverflow.com/questions/19115156/… Commented Apr 11, 2016 at 22:35

2 Answers 2

29

GNU make has an option to do a dry-run:

‘-n’

‘--just-print’

‘--dry-run’

‘--recon’

“No-op”. Causes make to print the recipes that are needed to make the targets up to date, but not actually execute them. Note that some recipes are still executed, even with this flag (see How the MAKE Variable Works). Also any recipes needed to update included makefiles are still executed.

So for your situation, just run make -n install to see the commands that make would execute.

1
  • 1
    BTW, the -n, --justprint, --dry-run and --recon options also all work in CMake. You can check this using cmake --help or man cmake. The four options seem to be equivalent/synonymous. Commented Jun 26, 2023 at 20:25
9

Any version of make has a -n option (see POSIX description of make), but the shell has no corresponding option (see for example Show commands without executing them).

To aggravate the situation, if you happen to use automake, it pastes-in large chunks of boilerplate scripting (which its developers refer to as "recursive rules") which defeat the ability of anyone to use "make -n" and see what will happen.

Further reading:

2
  • Debugging Make Rules mentions remake. Have you used it ? Looks like remake --trace is all I want, but I'd appreciate comments before trying it. Thanks Commented May 22, 2024 at 9:43
  • no, I've not ("make -n" works well enough, and likely "remake" won't address the problems with automake) Commented May 22, 2024 at 19:08

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.