Regular expression for matching Unix shebang lines at the beginning of files
88
Build a utility that extracts interpreter information from script files.
Your task is to create a tool that processes script file content and extracts shebang lines when present. The tool should:
#!)#! prefixThe extracted shebang should include everything from #! up to (but not including) the first newline character.
#!/usr/bin/env node\nconsole.log("hello");, the extracted shebang should be #!/usr/bin/env node @test#!/bin/bash\necho "test", the extracted shebang should be #!/bin/bash @testconsole.log("hello");, the function should return null or undefined @test#!/usr/bin/python3 -u\nprint("hello"), the extracted shebang should include the arguments: #!/usr/bin/python3 -u @test@generates
/**
* Extracts the shebang line from script content
*
* @param {string} content - The script file content
* @returns {string|null} The complete shebang line including #!, or null if not present
*/
function extractShebang(content) {
// IMPLEMENTATION HERE
}
module.exports = { extractShebang };Provides regular expression pattern for matching shebang lines.
@satisfied-by
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