Thanks for the responses.
Seems the detection of $PS1 is controlled by the shell interpreter.
The /etc/file/magic configuration file plays a role. The shell interpreter uses that file to determine the shell's respective behavior. In that file the
!/bin/sh declaration is interpreted as a
Bourne shell. The
!/bin/bash declaration is interpreted as a
Bourne-Again shell.
The Bourne-Again shell will detect the $PS1 environment variable and the Bourne shell will not.
From the Advanced Bash-Scripting Guide, Chapter 2:
The sha-bang ( #!) [1] at the head of a script tells your system that this file is a set of commands to be fed to the command interpreter indicated. The #! is actually a two-byte [2] magic number, a special marker that designates a file type, or in this case an executable shell script (type man magic for more details on this fascinating topic). Immediately following the sha-bang is a path name. This is the path to the program that interprets the commands in the script, whether it be a shell, a programming language, or a utility. This command interpreter then executes the commands in the script, starting at the top (the line following the sha-bang line), and ignoring comments. [3]
From the Bash Reference Manual, 6.2 Bash Startup Files:
Since a shell invoked as sh does not attempt to read and execute commands from any other startup files . . .
This would indicate that despite the sym link between /bin/sh and /bin/bash, when invoked using the /bin/sh declaration, bash will not read and execute the bash startup files. That includes /etc/profile, etc/bashrc, ~/.bashrc, etc. Hence the $PS1 environment variable is unavailable when a script is invoked with !/bin/sh.
From the Advanced Bash-Scripting Guide,, Chapter 31:
Using Bash-specific functionality in a Bourne shell script (#!/bin/sh) on a non-Linux machine may cause unexpected behavior. A Linux system usually aliases sh to bash, but this does not necessarily hold true for a generic UNIX machine.
A shell script headed by #!/bin/sh will not run in full Bash-compatibility mode. Some Bash-specific functions might be disabled. Scripts that need complete access to all the Bash-specific extensions should start with #!/bin/bash.
The detection of the $PS1 variable is a Bourne-Again shell feature and is unavailable in the generic Bourne shell.
From the Advanced Bash-Scripting Guide,, Chapter 33-10:
Note that /bin/sh is a link to /bin/bash in Linux and certain other flavors of UNIX, and a script invoked this way disables extended Bash functionality.
Perhaps then the question is not how to detect $PS1, which is a Bourne-Again shell feature, but how to detect or invoke interactive mode in a portable manner across both the Bourne and Bourne-Again shells, or any shell. One trick for better portability would seem to be to use the
/usr/bin/env declaration, but that trick basically is the same as using the !/bin/bash declaration.
The !/bin/sh declaration ensures better portability (POSIX compliance) between operating systems. Hence my use of the !/bin/sh declaration in my shell scripts. Which is why originally I tried to detect the contents of
$- rather than $PS1. I must have run across a lot of this information long ago and that got lost in the cobwebs of my mind.

So why doesn't
$- work correctly?
Once upon a time I read that the
$- variable detection is supposed to work across various shells and be more portable. Apparently that information is incorrect. I'd like to know when the $- detection method works within a script. My script always detects the variable but never sees the variable as confirming interactive mode.
When I start my script prefixed with the
sh -i command, then the $- variable confirms interactive mode.
For the immediate issue I can change my script declaration to !/bin/bash and obtain the dual effects (interactive versus non-interactive) I described in my original post. Yet I would like a more portable method for toggling between interactive and non-interactive mode when running a script directly from the command line.
I suspect many people do not know about these subtle differences if they developed the habit of always using one declaration or the other.
Feel free to add information to help better clarify these subtle quirks.