2

I'm a sucker for javascript, and i'm increasingly drawn towards writing script utilities for my everyday needs.

Currently I writing these utilities in bash scripts, but i'm not so proficient with shell scripting. I'm wondering if

  • any of you have ever come across an interpreter for javascript
  • any other convenient language that you use to write script utlitities in (like csh/perl)

[migrated from p.se]

I got one answer on p.se about Rhino. Is there anyway to run spidermonkey as a js interpreter on linux (and optionally windows)?

1
  • I know that V8 has been used to create server-run instances of javascript apps, an example being Node.js. Maybe see how Node.js is invoked...?
    – J Mac
    Oct 13, 2010 at 9:39

4 Answers 4

1

It is definitely possible to run SpiderMonkey at the command line. Fedora for one includes it in the js package, and there is documentation that shows how to build it.

Do note that XML and DOM handling is actually provided by the browser, and you'll need something like XML for <SCRIPT> if you want to use them at the command line.

I still prefer Python or Bash scripts whenever appropriate though.

0

You may look at javascript-interpreter-to-replace-python question from stackoverflow. Personally I would rather use Python/Ruby for system scripting.

0

try NodeJs

It has loads or modules to help writing scripts to run on command line. Here is one of the library that can be used to write task based command line tools.

https://github.com/cowboy/grunt

0

Check out Nacre.sh. It's a JavaScript interpreter based on NodeJS that provides common Bash functions like ls, cd, stat, mkdir, etc. I believe this will be the best way for you to stay proficient using JavaScript while taking advantage of a Bash background.

Examples:

// list items of the current directory
> ls()
[
  '.git',
  '.gitignore',
  '.idea',
  'LICENSE',
  'README.md',
  'docs',
  'gatsby-theme-doctornpm',
  'node_modules',
  'package-lock.json',
  'package.json'
]

// display info about a file
> stat('package.json')
{
  name: 'package.json',
  type: 'file',
  size: 844,
  createdAt: 2022-02-10T10:20:52.844Z,
  modifiedAt: 2022-02-12T09:48:15.158Z,
  owner: 'ninroot',
  group: 'staff'
}

> ls.map(stat)
// display info about each element of the current directory

You must log in to answer this question.

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