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

时间:2012-04-19 06:36:31

标签: ruby bash lua

如果我有BASH脚本,请执行以下操作:

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

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

1 个答案:

答案 0 :(得分:2)

您可以将源嵌入“here here”(在该联系人的manpage中搜索),并在bash脚本的运行时,在/ tmp或您希望执行它们的任何地方创建脚本;或者,如果他们接受来自stdin的输入,你可以将“here document”传递给脚本引擎。

我不太了解Ruby或Lua,但这里有一些Python来自Bash:

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