Lua或Ruby的源代码能够在BASH脚本中使用吗?

如果我有一个BASH脚本,就像这样:

#!/bin/bash
cp file1.txt file2.txt

我能否在BASH脚本中添加其他语言的源代码,比如存储在同一个文件中的Lua或Ruby代码?

原文链接 https://stackoverflow.com/questions/10222815

点赞
stackoverflow用户493161
stackoverflow用户493161

你可以在“here document”中嵌入源码(在 manpage 中搜索该字符串),并在 bash 脚本运行时创建脚本在 /tmp 或您希望执行它们的任何位置。或者,如果脚本引擎接受 stdin 输入,您可以将“here document”管道传递给它们。

我不了解太多 Ruby 或 Lua,但以下是通过 Bash 传递给 Python 的一些示例代码:

jcomeau@intrepid:/tmp$ cat <<EOF | python -
print "this is a test"
print "so is this"
import sys, os
print sys.path, os.getcwd()
EOF
2012-04-19 06:39:42