Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Comment continuation needed on first comment following shebang #1044

Closed
nicowilliams opened this issue Dec 14, 2015 · 3 comments
Closed

Comment continuation needed on first comment following shebang #1044

nicowilliams opened this issue Dec 14, 2015 · 3 comments

Comments

@nicowilliams
Copy link
Contributor

Historically shebangs allow only one argument in the shebang line. This means that if the script author doesn't know the path to the script interpreter and they need to pass any additional arguments to said interpreter, then they can't write the script.

The typical thing to do is this:

#!/bin/sh
# this comment is here just for the continuation so foo interpret doesn't eval this next line \
exec jq -f "$0" "$@"

But jq does not have comment continuations now, so adding them now would break backwards compatibility. But I think it'd be safe to scan for the shebang and continued comment on the first line in main() (as opposed to in src/parser.y). Then the above would work and there chance of breakage would be astronomically small.

nicowilliams added a commit to nicowilliams/jq that referenced this issue Dec 15, 2015
Allow a continuation on a comment immediately after a shebang to make
this traditional hack possible:

    #!/bin/sh
    # this next line is ignored by jq \
    exec jq -f "$0" "$@"
    # jq code follows

But continue only on the first line following a shebang, and only if
it's a comment.
@pkoppstein
Copy link
Contributor

The FAQ now documents the exec jq trick.

@nicowilliams
Copy link
Contributor Author

Thanks @pkoppstein.

mark-kubacki pushed a commit to mark-kubacki/jq that referenced this issue Aug 19, 2016
Allow a continuation on a comment immediately after a shebang to make
this traditional hack possible:

    #!/bin/sh
    # this next line is ignored by jq \
    exec jq -f "$0" "$@"
    # jq code follows

But continue only on the first line following a shebang, and only if
it's a comment.
@averca7
Copy link

averca7 commented Dec 1, 2021

](url)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants