Is there a Terminal command to know the macOS installed but from an external hard drive or from macOS recovery? How can I know the macOS version (such as 10.12.1) installed on the startup drive if I don't have the password (or has filevault encryption and I don't have the password).  I wonder if there's a way to know it by using a Terminal command from macOS recovery or by starting from an External storage disk.
The ProductVersion is stored within the SystemVersion.plist file in CoreServices. This can be read using defaults:

defaults read /System/Library/CoreServices/SystemVersion ProductVersion


When you're accessing the startup disk from another volume, you'll need to provide the full path to both defaults and /System:

/Volumes/Macintosh\ HD/usr/bin/defaults read /Volumes/Macintosh\ HD/usr/bin/System/Library/CoreServices/SystemVersion ProductVersion