0

I seem to remember that when executing a shell command there should be an option to "simulate" the result of that command, like making the system work but in a fictitious way, just saying what the output of the command would be. Is that true for all (or even for some) commands? If so, do you know how to do it?

1

3 Answers 3

2

Some commands may have such an option (like -s for apt-get, or -n for rename), but in general this is neither true nor possible.

1

That's program-specific, many command come with such an option, take rename

-n, -nono
  No action: print names of files to be renamed, but don't rename.

or mount for example:

-f, --fake
  Causes everything to be done except for the actual system call;
  if it's  not  obvious,  this  ``fakes'' mounting  the  filesystem.
  This option is useful in conjunction with the -v flag to determine
  what the mount command is trying to do.

See the correspondent man pages for these options.


A safe testing environment where you can virtually do what you want is a Virtual Machine, see and , e.g. How to install Ubuntu on VirtualBox?

0

You may be conflating that some commands have dry-run or simulate flags with that feature being present in the shell.

To complicate matters the sh and bash shells both respect the -n noexec flags for non interactive shells. However with those flags the commands are read but not executed. The intent is to allow some basic syntax checking. In the following code block you can see that the effect of the flag is not much different than looking at the script in a text editor.

bash -n -v ~/Documents/Scripts/Test2.sh
#!/bin/bash -nx

te="bob's your uncle"

echo $te

echo $te | sed 's/uncle/father/g'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .