CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-shebang-regex

Regular expression for matching Unix shebang lines at the beginning of files

88

1.54x
Overview
Eval results
Files

task.mdevals/scenario-4/

Script Interpreter Analyzer

Build a utility that analyzes script files and extracts information about their interpreters.

Requirements

Your utility should read script files and extract the interpreter path (the part after #!) from shebang lines. The extracted interpreter path should NOT include the #! prefix itself.

Input

Scripts will be provided as strings. Each script may or may not have a shebang line.

Output

For scripts with shebangs, return an object containing:

  • hasShebang: boolean indicating if a shebang was found
  • interpreterPath: the interpreter path without the #! prefix (or null if no shebang)

For scripts without shebangs, return:

  • hasShebang: false
  • interpreterPath: null

Edge Cases

  • Scripts with no shebang should be handled gracefully
  • Shebang must be at the start of the file to be valid
  • The interpreter path may contain spaces and arguments

Test Cases

  • When analyzing a Python script with shebang #!/usr/bin/env python3, it returns interpreterPath: '/usr/bin/env python3' @test
  • When analyzing a script with no shebang, it returns hasShebang: false and interpreterPath: null @test
  • When analyzing a Bash script with shebang #!/bin/bash, it returns interpreterPath: '/bin/bash' @test

Implementation

@generates

API

/**
 * Analyzes a script and extracts interpreter information
 * @param {string} script - The script content as a string
 * @returns {{hasShebang: boolean, interpreterPath: string|null}}
 */
function analyzeScript(script) {
  // IMPLEMENTATION HERE
}

module.exports = { analyzeScript };

Dependencies { .dependencies }

shebang-regex { .dependency }

Provides regular expression for matching and parsing shebang lines.

Install with Tessl CLI

npx tessl i tessl/npm-shebang-regex

tile.json