Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Tweak FAQ answer for passing julia options in a script file. #34018

Merged
merged 1 commit into from
Dec 9, 2019

Conversation

fredrikekre
Copy link
Member

In particular, this now sets PROGRAM_FILE (and thus can be combined with https://docs.julialang.org/en/v1/manual/faq/#How-do-I-check-if-the-current-file-is-being-run-as-the-main-script?-1):

$ cat script1.jl
#!/bin/bash
#=
exec julia --color=yes --startup-file=no -e 'include(popfirst!(ARGS))' \
    "${BASH_SOURCE[0]}" "$@"
=#

@show PROGRAM_FILE

$ ./script1.jl 
PROGRAM_FILE = ""

$ cat script2.jl
#!/bin/bash
#=
exec julia --color=yes --startup-file=no "${BASH_SOURCE[0]}" "$@"
=#

@show PROGRAM_FILE

$ ./script2.jl 
PROGRAM_FILE = "./script2.jl"

cc @tkf, since you authored #29423, is there something I am missing here or is this strictly better?

@fredrikekre fredrikekre added the docs This change adds or pertains to documentation label Dec 4, 2019
@tkf
Copy link
Member

tkf commented Dec 4, 2019

is there something I am missing here or is this strictly better?

I think this is a trade-off (so I don't think it's strictly better, unfortunately). As mentioned in How do I catch CTRL-C in a script?, include(popfirst!(ARGS)) is actually useful if you want to catch InterruptException in a script. (Aside: It would be nice to have a command line flag (say) to make InterruptException capturable in a script without "sacrificing" PROGRAM_FILE; ref #29383).

But, for the purpose of FAQ, I agree mentioning the simplest usecase (as in this PR) is probably better.

@fredrikekre
Copy link
Member Author

I see, I can add the original version in a note then maybe.

@fredrikekre
Copy link
Member Author

@tkf I updated with the note, do you wanna take another look?

@KristofferC
Copy link
Member

If this is what determines if Ctrl-C can be caught:

julia/base/client.jl

Lines 284 to 286 in 6f69067

if !is_interactive
ccall(:jl_exit_on_sigint, Cvoid, (Cint,), 1)
end

an alternative would be to document that function instead of having the indirect workaround with using `-e 'include("...")'.

@tkf
Copy link
Member

tkf commented Dec 7, 2019

@fredrikekre Thanks for adding a note for include(popfirst!(ARGS)). The PR looks perfect to me! 👍

an alternative would be to document that function

@KristofferC I guess you are suggesting to wrap jl_exit_on_sigint as a Julia function and document it? Yes, that sounds like a cleaner solution.

@fredrikekre fredrikekre merged commit 83d7466 into master Dec 9, 2019
@fredrikekre fredrikekre deleted the fe/script-faq branch December 9, 2019 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants