bash - 如何在bash命令行上输出文件列表

标签 bash node.js command-line-arguments handlebars.js

我使用handlebars.js 为我们的单页应用程序渲染客户端模板(在node.js 服务器端使用Jade)。

我想在服务器端预编译 Handlebars 模板,并将它们捆绑为一个 JS 文件发送给客户端。

目前,我使用 handlebars 来编译模板,如下所示:

$ handlebars template1.handlebars template2.handlebars -f precompiled_templates.js

我想编写一个bash脚本,它可以读取目录中的所有*.handlebars文件,然后通过handlebars编译器运行它们。所以,如果我有一个像这样的目录:

templates/
  temp1.handlebars
  temp2.handlebars
  temp3.handlebars
  temp4.handlebars

在模板目录中运行我的 bash 脚本(或一行命令)本质上会运行以下 handlebars 命令:

$ handlebars temp1.handlebars temp2.handlebars temp3.handlebars temp4.handlebars -f precompiled_templates.js

有谁知道我如何编写 bash 脚本来将目录中的所有 Handlebars 文件像上面一样放到命令行上?

最佳答案

看起来您想要类似的东西

handlebars templates/*.handlebars -f precompiled_templates.js

除非您最终会在每个文件中添加"template"前缀。我首选的方法需要两行:

files=( templates/*.handlebars )
handlebars "${files[@]#templates/}" -f precompiled_templates.js.

第一行将所有所需的文件放入一个数组中。在第二行中,我们扩展数组的内容,但从生成的扩展中的每个元素中删除“templates/”前缀。

关于bash - 如何在bash命令行上输出文件列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12588402/

相关文章:

c# - 让 VS2010 提示我输入命令行参数

java - 从 Java 程序运行 Bash 以在 Raspberry Pi 上捕获网络摄像头图像

bash - 为什么管道传输到同一个文件在某些​​平台上不起作用?

linux - 用空格重命名文件

python - 使用 sed 根据条件解释多行

node.js - 在node.js中处理soap和wsdl webservice

mongodb - NodeJs Mongoose + Mongo,连接到本地主机

linux - 如何使用 putty 在 linux 服务器上安装 node.js

C 程序中的命令行参数(来自 shell)

compact-framework - C# Compact-Framework 友好的命令行解析器