Skip to content

Commit 83d7466

Browse files
authored
Tweak FAQ answer for passing julia options in a script file. (#34018)
1 parent beebfd3 commit 83d7466

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

doc/src/manual/faq.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ When a file is run as the main script using `julia file.jl` one might want to ac
6767
functionality like command line argument handling. A way to determine that a file is run in
6868
this fashion is to check if `abspath(PROGRAM_FILE) == @__FILE__` is `true`.
6969

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

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

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

104+
!!! note
105+
In order to [catch CTRL-C](@ref catch-ctrl-c) in the script you can use
106+
```julia
107+
#!/bin/bash
108+
#=
109+
exec julia --color=yes --startup-file=no -e 'include(popfirst!(ARGS))' \
110+
"${BASH_SOURCE[0]}" "$@"
111+
=#
112+
113+
@show ARGS # put any Julia code here
114+
```
115+
instead. Note that with this strategy [`PROGRAM_FILE`](@ref) will not be set.
116+
105117
## Functions
106118

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

0 commit comments

Comments
 (0)