Skip to content

Commit

Permalink
Tweak FAQ answer for passing julia options in a script file.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Dec 5, 2019
1 parent 6f69067 commit 80f59eb
Showing 1 changed file with 15 additions and 3 deletions.
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

0 comments on commit 80f59eb

Please sign in to comment.