GithubHelp home page GithubHelp logo

sgreben / subst Goto Github PK

View Code? Open in Web Editor NEW
14.0 3.0 0.0 66 KB

substitutes $variables in text. single binary, no dependencies. linux, osx, windows.

License: MIT License

Makefile 44.21% Go 55.79%
envsubst simpler variables substitution stdin stdout

subst's Introduction

subst - substitute $variables in text

subst parses its arguments as KEY=VALUE pairs, substitutes $KEYs by VALUEs in stdin, and writes the result to stdout.

screenshot

Get it

Using go get:

go get -u github.com/sgreben/subst

Or download the binary from the releases page.

# Linux
curl -LO https://github.com/sgreben/subst/releases/download/1.1.1/subst_1.1.1_linux_x86_64.zip
unzip subst_1.1.1_linux_x86_64.zip

# OS X
curl -LO https://github.com/sgreben/subst/releases/download/1.1.1/subst_1.1.1_osx_x86_64.zip
unzip subst_1.1.1_osx_x86_64.zip

# Windows
curl -LO https://github.com/sgreben/subst/releases/download/1.1.1/subst_1.1.1_windows_x86_64.zip
unzip subst_1.1.1_windows_x86_64.zip

Use it

subst uses key=value mappings given as CLI arguments, reads from stdin, and writes to stdout. The stdin input is line-buffered.


subst [OPTIONS] [KEY=VAL [KEY=VAL...]]

Usage of subst:
  -q    suppress all logs
  -escape string
        set the escape string. if set, a '$' preceded by the escape string does not lead to expansion
  -unknown value
        handling of unknown keys, one of [ignore empty error] (default ignore)

Examples

$ cat template.yaml
name: $NAME
url: $URL
comment: $COMMENT

$ cat template.yaml | subst -q NAME=jp  URL=github.com/sgreben/jp COMMENT=
name: jp
url: github.com/sgreben/jp
comment:

$ cat template.yaml | subst -q NAME=jp
name: jp
url: $URL
comment: $COMMENT

$ cat template.yaml | subst -q -unknown=empty NAME=jp
name: jp
url:
comment:

Without the -q flag, subst also prints to stderr:

2018/04/16 15:18:37 undefined key: $URL, using value "$URL"
2018/04/16 15:18:37 undefined key: $COMMENT, using value "$COMMENT"

You can substitute environment variables (like envsubst) by letting the shell substitute their values:

$ subst USER="$USER" SHELL="$SHELL"
$USER
sgreben
$SHELL
/bin/zsh

To ignore occurrences of defined variables, you can define an escape string using the -escape flag:

$ echo 'unescaped: $X, ${X}. escaped: \$X, \${X}.' | subst -escape '\' X=value
unescaped: value, value. escaped: $X, ${X}.

Comments

Feel free to leave a comment or create an issue.

subst's People

Contributors

sgreben avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

subst's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.