Function parse_shebang_from_file

Source
pub fn parse_shebang_from_file<P: AsRef<Path>>(path: P) -> Result<TagSet>
Expand description

Parse shebang line from an executable file and return interpreter tags.

This function reads the first line of an executable file to extract shebang information and determine the script interpreter.

§Arguments

  • path - Path to the executable file

§Returns

A set of tags for the interpreter found in the shebang line. Returns an empty set if:

  • The file is not executable
  • No shebang is found
  • The interpreter is not recognized

§Errors

Returns an error if the file cannot be accessed or read.

§Examples

use file_identify::parse_shebang_from_file;

let tags = parse_shebang_from_file(&script_path).unwrap();
assert!(tags.contains("python"));