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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions doc/src/manual/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ When a file is run as the main script using `julia file.jl` one might want to ac
functionality like command line argument handling. A way to determine that a file is run in
this fashion is to check if `abspath(PROGRAM_FILE) == @__FILE__` is `true`.

### How do I catch CTRL-C in a script?
### [How do I catch CTRL-C in a script?](@id catch-ctrl-c)

Running a Julia script using `julia file.jl` does not throw
[`InterruptException`](@ref) when you try to terminate it with CTRL-C
Expand All @@ -90,8 +90,7 @@ use `exec` to replace the process to `julia`:
```julia
#!/bin/bash
#=
exec julia --color=yes --startup-file=no -e 'include(popfirst!(ARGS))' \
"${BASH_SOURCE[0]}" "$@"
exec julia --color=yes --startup-file=no "${BASH_SOURCE[0]}" "$@"
=#

@show ARGS # put any Julia code here
Expand All @@ -102,6 +101,19 @@ script. Julia ignores this part since it is a multi-line comment for
Julia. The Julia code after `=#` is ignored by `bash` since it stops
parsing the file once it reaches to the `exec` statement.

!!! note
In order to [catch CTRL-C](@ref catch-ctrl-c) in the script you can use
```julia
#!/bin/bash
#=
exec julia --color=yes --startup-file=no -e 'include(popfirst!(ARGS))' \
"${BASH_SOURCE[0]}" "$@"
=#

@show ARGS # put any Julia code here
```
instead. Note that with this strategy [`PROGRAM_FILE`](@ref) will not be set.

## Functions

### I passed an argument `x` to a function, modified it inside that function, but on the outside, the variable `x` is still unchanged. Why?
Expand Down