如何在 BASH 到 运行 julia 命令中的 heredoc 函数中使用变量的值
How to use the value of a variable in a heredoc function in BASH to run a julia command
我是 BASH 和 Julia 的新手,我正在尝试执行以下步骤:
- 在变量中保存文件路径
- 在 julia 命令中使用这个变量,我通过使用 heredoc 函数 bash 设法执行了该命令
有效的硬编码命令:
cat << "EOF" | julia --project=.
module test
ARGS=["/path/To/My/Directory"]
include("nameOfMyProject.jl")
end
EOF
问题是,我想用变量值交换硬编码路径。
我试过了:
path="/path/To/My/Directory"
cat << "EOF" | julia --project=.
module test
ARGS=[$path]
include("nameOfMyProject.jl")
end
EOF
但是,这不起作用。我读到我应该尝试使用 <
针对此问题的解决方法:
如果其他人有同样的问题,我将此添加以供参考。可以很好地解决问题的格式是:
path="/path/To/My/Directory"
julia --project=. <<EOF
module test
ARGS=["$path"]
include("nameOfMyProject.jl")
end
EOF
感谢 Jetchisel 和 Jens
来自 bash 手册(强调我的):
Here Documents
This type of redirection instructs the shell to read input from the
current source until a line containing only delimiter (with no trailing
blanks) is seen. All of the lines read up to that point are then used
as the standard input (or file descriptor n if n is specified) for a
command.
The format of here-documents is:
[n]<<[-]word
here-document
delimiter
No parameter and variable expansion, command substitution, arithmetic
expansion, or pathname expansion is performed on word. If any part of
word is quoted, the delimiter is the result of quote removal on word,
and the lines in the here-document are not expanded. If word is
unquoted, all lines of the here-document are subjected to parameter
expansion, command substitution, and arithmetic expansion, the
character sequence \<newline>
is ignored, and \ must be used to quote
the characters \, $, and `.
所以你只需要
julia --project=. << EOF
...$FOO...
EOF
我是 BASH 和 Julia 的新手,我正在尝试执行以下步骤:
- 在变量中保存文件路径
- 在 julia 命令中使用这个变量,我通过使用 heredoc 函数 bash 设法执行了该命令
有效的硬编码命令:
cat << "EOF" | julia --project=.
module test
ARGS=["/path/To/My/Directory"]
include("nameOfMyProject.jl")
end
EOF
问题是,我想用变量值交换硬编码路径。 我试过了:
path="/path/To/My/Directory"
cat << "EOF" | julia --project=.
module test
ARGS=[$path]
include("nameOfMyProject.jl")
end
EOF
但是,这不起作用。我读到我应该尝试使用 < 针对此问题的解决方法:
如果其他人有同样的问题,我将此添加以供参考。可以很好地解决问题的格式是: 感谢 Jetchisel 和 Jenspath="/path/To/My/Directory"
julia --project=. <<EOF
module test
ARGS=["$path"]
include("nameOfMyProject.jl")
end
EOF
来自 bash 手册(强调我的):
Here Documents
This type of redirection instructs the shell to read input from the current source until a line containing only delimiter (with no trailing blanks) is seen. All of the lines read up to that point are then used as the standard input (or file descriptor n if n is specified) for a command.
The format of here-documents is:
[n]<<[-]word
here-document
delimiter
No parameter and variable expansion, command substitution, arithmetic expansion, or pathname expansion is performed on word. If any part of word is quoted, the delimiter is the result of quote removal on word, and the lines in the here-document are not expanded. If word is unquoted, all lines of the here-document are subjected to parameter expansion, command substitution, and arithmetic expansion, the character sequence
\<newline>
is ignored, and \ must be used to quote the characters \, $, and `.
所以你只需要
julia --project=. << EOF
...$FOO...
EOF