3

Monitor mode can be disabled inside of Bash using set +m. I would like to know whether it is possible to do this using Bash's arguments on invocation. That is, something like:

bash +o monitor 

or perhaps:

bash +m 

I have been looking at Bash's manpage for a while now and it is starting to seem like this is not possible.

2 Answers 2

1

It looks impossible to disable monitor mode for an interactive bash session with command-line options/arguments at invocation time, unless you cheat. I determined this by digging into the source code, primarily the files shell.c and jobs.c. I cloned the repo locally with git clone git://git.savannah.gnu.org/bash.git so that it was easier to search.

It's impossible to disable monitor mode at invocation time because the bash startup sequence enables monitor mode after processing the various options/arguments. Even if you invoke bash +o monitor, where bash will temporarily set the option in the parse_shell_options function, it later calls a function named set_job_control (again, when in interactive mode) which sets the global variable "job_control" to true (the value of the "interactive" argument).

Note that the potential +O shopt route via the run_shopt_alist function is a dead-end, despite the interactive shopt command being able to disable monitor mode with shopt -o -u monitor, because monitor mode is not a native shopt option.

The cheat method relies on an external file; you'd create an alternative bashrc file containing set +m (and optionally sourcing your real ~/.bashrc), then invoke bash as:

bash --rcfile /path/to/that/alternate_bashrc_file 

This works because the rcfile parsing is done (with the run_startup_files function) after set_job_control is called, so it's able to finally set the shell option.

2
  • I guess the catch with this cheat method is that monitor mode is still initially enabled in interactive mode but then automatically disabled by the alternative bashrc file, right? Commented Sep 6, 2021 at 10:58
  • That's right; monitor mode is disabled by the time you have a prompt. Commented Sep 6, 2021 at 11:58
1

It is possible to set monitor to disabled:

$ bash +o monitor -c 'shopt -op monitor' shopt +o monitor 

But only for non-interactive shells (scripts, one liners (-c) for example).

For interactive shells, even if you try, monitor is re-enabled:

$ bash +o monitor ~/.bashrc sourced $ shopt -op monitor set -o monitor $ exit 

But, as the bashrc file is loaded (as shown above), you can include a line to disable it.

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.