Function parse_shebang_from_file

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

Parse shebang line from an executable file and return raw shebang components.

This function reads the first line of an executable file to extract shebang information and return the raw command components, similar to Python’s identify.parse_shebang_from_file().

§Arguments

  • path - Path to the executable file

§Returns

A vector of raw shebang components. Returns an empty vector if:

  • The file is not executable
  • No shebang is found

§Errors

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

§Examples

use file_identify::parse_shebang_from_file;

let shebang = parse_shebang_from_file(&script_path).unwrap();
assert_eq!(shebang.get(0).unwrap(), "python3");