I'm finally getting around to getting more familiar with the shell after all these years. I was exploring the man page for bash and looking at the -D option, which, according to the manual:

   -D        A list of all double-quoted strings preceded by $ is  printed
             on  the standard output.  These are the strings that are sub-
             ject to language translation when the current locale is not C
             or  POSIX.   This  implies the -n option; no commands will be

However, on my mac it generates no output and dumps me into a new shell that seems to have less functionality than the original shell; the which command stopped working in this new shell.

Just wondering if someone can offer insight into what this option is for on the mac. I'm probably using it wrong, I'm sure.

2 Answers 2


On my mac, bash -D generates no output

bash -D (and its equivalent long option --dump-strings) reads commands from standard input or a file and extracts strings marked as translatable, that is, double-quoted strings that are preceded by a dollar sign, like $"Hello, world".

If bash -D is run without any input, as you did, it outputs nothing and starts a new shell (a special shell, see below.)

For example, for this simple script /tmp/script:

echo $"Hello, world"

bash -D outputs:

"Hello, world"

As you see, this is equivalent to searching for lines that match $"<text>" and removing the dollar sign.

More interesting is the output of the similar option --dump-po-strings, which is, as the Bash man page puts it, equivalent to -D, but the output is in the GNU gettext po (portable object) file format.:

bash --dump-po-strings /tmp/script
#: /tmp/script:2
msgid "Hello, world"
msgstr ""

This excellent article How to add localization support to your bash scripts provides more information on how to use this option.

bash -D dumps me into a new shell that seems to have less functionality than the original shell

That's right, the new shell doesn't react to any commands. The reason for this is that the -D option implies -n, which directs the shell to read commands but not execute them.

The -n option deserves an explanation: although a seemingly useless option at first glance, it is actually quite useful. bash -n does not only read commands but also validates them and complains if the syntax is not valid, so you can run bash -n <script name> to check a script for syntax errors without executing any command.

This means that after executing bash -D, the shell you get will happily accept your commands, check for syntax validity (and output an error if necessary) and do nothing. That's why which "doesn't work".

See Invoking Bash and The Set Builtin sections of the Bash Reference Manual for some background information on this behavior.

  • I ended up here while trying to make sense of a .sh file with this first line: #!/bin/bash -D The -D option seems to get ignored in this context. Can anyone comment about if this usage is actually ever warranted or not?
    – iwolf
    Dec 9, 2020 at 0:15
  • 1
    @iwolf Interesting, I can only think of it as a quick way to "disable" a script without changing the executable bits (that is, the script would still have mode 755/rwxr-xr-x but does nothing). Otherwise, I don't see how this could be ever useful at all. In my tests, such a script does nothing (except printing localizable strings, that is, double-quoted strings that are preceded by a dollar sign).
    – jaume
    Dec 9, 2020 at 12:15

It's intended to extract all the localizable strings without running the script, but it isn't very useful even for that limited purpose and I believe it has long been deprecated. If you want to see it doing something:

% printf "foo\n\$\"bar\"\n" | bash -D

You must log in to answer this question.

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