strider
strider

Reputation: 5954

Reliably determine what shell (cmd, bash, or etc) was used to run node.js script

As the title states, I'd like determine what shell (cmd, bash, or etc) was used to run the node.js script (from within the script).

While detecting the OS with the os module can give some clues, it is not enough is some instances, such as as if I were executing from bash on win32 through a terminal like GitBash or Cygwin.

Is there a property somewhere on the process object that has this information?

*Edit: While process.env.SHELL is an option, it is not always populated and maybe undefined when using some terminals

Upvotes: 2

Views: 188

Answers (1)

Inian
Inian

Reputation: 85630

You can use the process.env.SHELL property to get that as seen in the official documentation,

The process.env property returns an object containing the user environment. An example of this object looks like:

{
  TERM: 'xterm-256color',
  SHELL: '/usr/local/bin/bash',
  USER: 'maciej',
  PATH: '~/.bin/:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin',
  PWD: '/Users/maciej',
  EDITOR: 'vim',
  SHLVL: '1',
  HOME: '/Users/maciej',
  LOGNAME: 'maciej',
  _: '/usr/local/bin/node'
}

Upvotes: 2

Related Questions