V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
xinhangliu
V2EX  ›  程序员

有没有用 shell scripts 实现的模板引擎?

  •  
  •   xinhangliu · Oct 8, 2018 · 4240 views
    This topic created in 2771 days ago, the information mentioned may be changed or developed.
    13 replies    2018-10-08 14:26:09 +08:00
    azh7138m
        1
    azh7138m  
       Oct 8, 2018 via Android
    https://github.com/dontsueme/shtpl

    类似这种东西吗?
    xinhangliu
        2
    xinhangliu  
    OP
       Oct 8, 2018
    @azh7138m 对,但这个并不是纯 shell scripts 实现的。
    wizardoz
        3
    wizardoz  
       Oct 8, 2018
    为啥要用 shell 来实现这玩意我好奇怪?把现有的模板引擎支持标准输入输出调用,它就可以在 shell 中使用了啊。
    xinhangliu
        4
    xinhangliu  
    OP
       Oct 8, 2018
    @wizardoz 想用来配置配置文件,所以最好能不引入依赖。
    azh7138m
        5
    azh7138m  
       Oct 8, 2018 via Android
    @xinhangliu 是 shell 实现的啊,我看没有依赖
    congeec
        6
    congeec  
       Oct 8, 2018
    shell 现有的特性足够当模板引擎了
    geelaw
        7
    geelaw  
       Oct 8, 2018
    我的 blog 就是 PowerShell,不过也有外部命令。
    Firxiao
        8
    Firxiao  
       Oct 8, 2018
    shell 的话用 awk 实现过一个配置调用. 不过顶多算可用 不够优雅, 感觉还是 Python 好用些.
    dudesun
        9
    dudesun  
       Oct 8, 2018   ❤️ 1
    Mo - Mustache Templates in Bash

    https://github.com/tests-always-included/mo
    yanaraika
        10
    yanaraika  
       Oct 8, 2018
    #!/usr/bin/env bash

    eval "echo \"$(cat $1)\""

    用法:
    temp.tmpl
    Hello ${MY_USERNAME}

    MY_USERNAME="foobar" ./render.sh temp.tmpl

    输出
    Hello foobar
    yanaraika
        11
    yanaraika  
       Oct 8, 2018
    @yanaraika 注意已经有的环境变量以及安全问题
    kkeybbs
        12
    kkeybbs  
       Oct 8, 2018 via iPhone
    配置文件不会太复杂,目前装了 gettext 用 envsubst
    agagega
        13
    agagega  
       Oct 8, 2018 via iPhone
    我想知道有没有用 Python Ruby 这类正经脚本语言做的 Shell
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2900 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 58ms · UTC 11:24 · PVG 19:24 · LAX 04:24 · JFK 07:24
    ♥ Do have faith in what you're doing.