diff --git a/doc/src/manual/faq.md b/doc/src/manual/faq.md index e3a94bdf9c1cb..00e4cf0e459be 100644 --- a/doc/src/manual/faq.md +++ b/doc/src/manual/faq.md @@ -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 @@ -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 @@ -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?