Regular expression for matching Unix shebang lines at the beginning of files
88
Build a utility that analyzes script files and extracts information about their interpreters.
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.
Scripts will be provided as strings. Each script may or may not have a shebang line.
For scripts with shebangs, return an object containing:
hasShebang: boolean indicating if a shebang was foundinterpreterPath: the interpreter path without the #! prefix (or null if no shebang)For scripts without shebangs, return:
hasShebang: falseinterpreterPath: null#!/usr/bin/env python3, it returns interpreterPath: '/usr/bin/env python3' @testhasShebang: false and interpreterPath: null @test#!/bin/bash, it returns interpreterPath: '/bin/bash' @test@generates
/**
* 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 };Provides regular expression for matching and parsing shebang lines.
Install with Tessl CLI
npx tessl i tessl/npm-shebang-regexdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9