@@ -67,7 +67,7 @@ When a file is run as the main script using `julia file.jl` one might want to ac
67
67
functionality like command line argument handling. A way to determine that a file is run in
68
68
this fashion is to check if ` abspath(PROGRAM_FILE) == @__FILE__ ` is ` true ` .
69
69
70
- ### How do I catch CTRL-C in a script?
70
+ ### [ How do I catch CTRL-C in a script?] ( @ id catch-ctrl-c)
71
71
72
72
Running a Julia script using ` julia file.jl ` does not throw
73
73
[ ` InterruptException ` ] ( @ref ) when you try to terminate it with CTRL-C
@@ -90,8 +90,7 @@ use `exec` to replace the process to `julia`:
90
90
``` julia
91
91
# !/bin/bash
92
92
#=
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]}" "$@"
95
94
=#
96
95
97
96
@show ARGS # put any Julia code here
@@ -102,6 +101,19 @@ script. Julia ignores this part since it is a multi-line comment for
102
101
Julia. The Julia code after ` =# ` is ignored by ` bash ` since it stops
103
102
parsing the file once it reaches to the ` exec ` statement.
104
103
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
+
105
117
## Functions
106
118
107
119
### 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