Skip to content

datafusion-cli: ignore hashbang at top of script #11880

@stephenmw

Description

@stephenmw

Is your feature request related to a problem or challenge?

I would like to create executable scripts using datafusion-cli as an interpreter.

For example, given the following tmp.sql file:

#!/usr/bin/env -S datafusion-cli -f
SELECT 1;

I would like to be able to run the following successfully:

$ chmod 755 tmp.sql
$ ./tmp.sql

Instead, I get this:

$ chmod 755 tmp.sql
$ ./tmp.sql
DataFusion CLI v40.0.0
SQL error: ParserError("Expected an SQL statement, found: #!")
$

Describe the solution you'd like

When datafusion-cli is run on a file it should ignore the first line of the file if it begins with '#!' as the first two characters.

I believe no valid SQL file can begin with '#!'. Therefore it is safe to make this rule. If for some reason someone wanted to begin a statement with #!, they can put a return at the beginning of the file. '#!' must be the first two characters of the file to be a valid hashbang.

Describe alternatives you've considered

No response

Additional context

https://en.wikipedia.org/wiki/Shebang_(Unix)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions