From 2919f95511470f4ae3547d9c178e4dff68e5244e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lavoie?= Date: Thu, 12 Jan 2017 21:34:03 -0800 Subject: [PATCH 01/14] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2e4491a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Sébastien Lavoie + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From af4342585e5286213343c3b37d6de5bc28207efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lavoie?= Date: Mon, 17 Jul 2017 23:50:14 -0700 Subject: [PATCH 02/14] Added tips on invoking while reading variables from a file --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3342eeb..828ec14 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,18 @@ See http://blog.lavoie.sl/2012/11/simple-templating-system-using-bash.html for o ## Usage - VAR=value templater.sh template +```sh +# Passing arguments directly +VAR=value templater.sh template + +# Evaluate /tmp/foo and pass those variables to the template +# Useful for defining variables in a file +# Parentheses are important for not polluting the current shell +(set -a && . /tmp/foo && templater.sh template) + +# A variant that does NOT pass current env variables to the templater +sh -c "set -a && . /tmp/foo && templater.sh template" +``` ## Examples -See examples/ \ No newline at end of file +See examples/ From 21cd0c550afb0c8cbdecd75c7d3522ff870505a7 Mon Sep 17 00:00:00 2001 From: Sebastien Lavoie Date: Tue, 18 Jul 2017 00:48:38 -0700 Subject: [PATCH 03/14] Cleanup escaping --- templater.sh | 64 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 16 deletions(-) diff --git a/templater.sh b/templater.sh index 488b3d1..5ef4add 100755 --- a/templater.sh +++ b/templater.sh @@ -18,47 +18,79 @@ var_value() { eval echo \$$1 } -replaces="" +## +# Escape custom characters in a string +# WARNING: if \ is escaped, it must be the first +# Example: escape "ab'\c" '\' "'" ===> ab\'\\c +# +function escape_chars() { + local content="${1}" + shift + + for char in "$@"; do + if [ "${char}" = '$' -o "${char}" = '\' -o "${char}" = '/' ]; then + char="\\${char}" + fi + content="$(echo "${content}" | sed -e "s/${char}/\\\\${char}/g")" + done + + echo "${content}" +} + +function echo_var() { + local var="${1}" + local content="${2}" + local escaped="$(escape_chars "${content}" '\' '"')" + + echo "${var}=\"${escaped}\"" +} + +declare -a replaces +replaces=() # Reads default values defined as {{VAR=value}} and delete those lines # There are evaluated, so you can do {{PATH=$HOME}} or {{PATH=`pwd`}} # You can even reference variables defined in the template before -defaults=$(grep -oE '^\{\{[A-Za-z0-9_]+=.+\}\}' "$template" | sed -e 's/^{{//' -e 's/}}$//') +defaults=$(grep -oE '^\{\{[A-Za-z0-9_]+=.+\}\}$' "${template}" | sed -e 's/^{{//' -e 's/}}$//') +IFS=$'\n' for default in $defaults; do - var=$(echo "$default" | grep -oE "^[A-Za-z0-9_]+") - current=`var_value $var` + var=$(echo "${default}" | grep -oE "^[A-Za-z0-9_]+") + current="$(var_value "${var}")" # Replace only if var is not set - if [[ -z "$current" ]]; then - eval $default + if [[ -n "$current" ]]; then + eval "$(echo_var "${var}" "${current}")" + else + eval "${default}" fi # remove define line - replaces="-e '/^{{$var=/d' $replaces" - vars="$vars -$current" + replaces+=("-e") + replaces+=("/^{{${var}=/d") + vars="${vars} ${var}" done -vars=$(echo $vars | sort | uniq) +vars=$(echo $vars | tr " " "\n" | sort | uniq) if [[ "$2" = "-h" ]]; then for var in $vars; do - value=`var_value $var` - echo "$var = $value" + value="$(var_value "${var}")" + echo_var "${var}" "${value}" done exit 0 fi # Replace all {{VAR}} by $VAR value for var in $vars; do - value=`var_value $var` + value="$(var_value $var)" if [[ -z "$value" ]]; then echo "Warning: $var is not defined and no default is set, replacing by empty" >&2 fi # Escape slashes - value=$(echo "$value" | sed 's/\//\\\//g'); - replaces="-e 's/{{$var}}/$value/g' $replaces" + value="$(escape_chars "${value}" '\' '/' ' ')"; + replaces+=("-e") + replaces+=("s/{{${var}}}/${value}/g") done -eval sed $replaces "$template" \ No newline at end of file +sed "${replaces[@]}" "${template}" From dfe9c5b2b1dfbd9bc2867157557c1244f2c2163e Mon Sep 17 00:00:00 2001 From: Sebastien Lavoie Date: Tue, 18 Jul 2017 00:58:37 -0700 Subject: [PATCH 04/14] shellcheck lint --- templater.sh | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/templater.sh b/templater.sh index 5ef4add..76e87fd 100755 --- a/templater.sh +++ b/templater.sh @@ -15,12 +15,12 @@ if [[ -z "$vars" ]]; then fi var_value() { - eval echo \$$1 + var="${1}" + eval echo \$"${var}" } ## # Escape custom characters in a string -# WARNING: if \ is escaped, it must be the first # Example: escape "ab'\c" '\' "'" ===> ab\'\\c # function escape_chars() { @@ -28,10 +28,7 @@ function escape_chars() { shift for char in "$@"; do - if [ "${char}" = '$' -o "${char}" = '\' -o "${char}" = '/' ]; then - char="\\${char}" - fi - content="$(echo "${content}" | sed -e "s/${char}/\\\\${char}/g")" + content="${content//${char}/\\${char}}" done echo "${content}" @@ -40,7 +37,7 @@ function escape_chars() { function echo_var() { local var="${1}" local content="${2}" - local escaped="$(escape_chars "${content}" '\' '"')" + local escaped="$(escape_chars "${content}" "\\" '"')" echo "${var}=\"${escaped}\"" } @@ -70,7 +67,7 @@ for default in $defaults; do vars="${vars} ${var}" done -vars=$(echo $vars | tr " " "\n" | sort | uniq) +vars="$(echo "${vars}" | tr " " "\n" | sort | uniq)" if [[ "$2" = "-h" ]]; then for var in $vars; do @@ -82,13 +79,13 @@ fi # Replace all {{VAR}} by $VAR value for var in $vars; do - value="$(var_value $var)" + value="$(var_value "${var}")" if [[ -z "$value" ]]; then echo "Warning: $var is not defined and no default is set, replacing by empty" >&2 fi # Escape slashes - value="$(escape_chars "${value}" '\' '/' ' ')"; + value="$(escape_chars "${value}" "\\" '/' ' ')"; replaces+=("-e") replaces+=("s/{{${var}}}/${value}/g") done From e6e648b3d3e14a5d593964781ed5dca4db444b26 Mon Sep 17 00:00:00 2001 From: Sebastien Lavoie Date: Tue, 30 Jan 2018 18:33:48 -0800 Subject: [PATCH 05/14] Add travis-ci --- .travis.yml | 2 ++ examples/vhost-php.conf | 24 +++++++++--------------- examples/vhost-php.tpl.conf | 28 ++++++++++++++++++++++++++++ test.sh | 8 ++++++++ 4 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 .travis.yml create mode 100644 examples/vhost-php.tpl.conf create mode 100755 test.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3c14744 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,2 @@ +language: bash +script: ./test.sh diff --git a/examples/vhost-php.conf b/examples/vhost-php.conf index 682dacf..e7767a0 100644 --- a/examples/vhost-php.conf +++ b/examples/vhost-php.conf @@ -1,17 +1,11 @@ -{{LOG_DIR=/var/log/apache2}} -{{RUN_DIR=/var/run/php-fpm}} -{{FCGI=$RUN_DIR/$DOMAIN.fcgi}} -{{SOCKET=$RUN_DIR/$DOMAIN.sock}} -{{EMAIL=$USER@$DOMAIN}} -{{DOC_ROOT=/home/$USER/sites/$DOMAIN/htdocs}} - ServerAdmin {{EMAIL}} - ServerName {{DOMAIN}} - ServerAlias www.{{DOMAIN}} + ServerAdmin nobody@example.com + ServerName example.com + ServerAlias www.example.com - DocumentRoot "{{DOC_ROOT}}" + DocumentRoot "/home/nobody/sites/example.com/htdocs" - + AllowOverride All Order allow,deny Allow From All @@ -19,10 +13,10 @@ AddHandler php-script .php Action php-script /php5.fastcgi virtual - Alias /php5.fastcgi {{FCGI}} - FastCGIExternalServer {{FCGI}} -socket {{SOCKET}} + Alias /php5.fastcgi /var/run/php-fpm/example.com.fcgi + FastCGIExternalServer /var/run/php-fpm/example.com.fcgi -socket /var/run/php-fpm/example.com.sock LogLevel warn - CustomLog {{LOG_DIR}}/{{DOMAIN}}.access.log combined - ErrorLog {{LOG_DIR}}/{{DOMAIN}}.error.log + CustomLog /var/log/apache2/example.com.access.log combined + ErrorLog /var/log/apache2/example.com.error.log diff --git a/examples/vhost-php.tpl.conf b/examples/vhost-php.tpl.conf new file mode 100644 index 0000000..682dacf --- /dev/null +++ b/examples/vhost-php.tpl.conf @@ -0,0 +1,28 @@ +{{LOG_DIR=/var/log/apache2}} +{{RUN_DIR=/var/run/php-fpm}} +{{FCGI=$RUN_DIR/$DOMAIN.fcgi}} +{{SOCKET=$RUN_DIR/$DOMAIN.sock}} +{{EMAIL=$USER@$DOMAIN}} +{{DOC_ROOT=/home/$USER/sites/$DOMAIN/htdocs}} + + ServerAdmin {{EMAIL}} + ServerName {{DOMAIN}} + ServerAlias www.{{DOMAIN}} + + DocumentRoot "{{DOC_ROOT}}" + + + AllowOverride All + Order allow,deny + Allow From All + + + AddHandler php-script .php + Action php-script /php5.fastcgi virtual + Alias /php5.fastcgi {{FCGI}} + FastCGIExternalServer {{FCGI}} -socket {{SOCKET}} + + LogLevel warn + CustomLog {{LOG_DIR}}/{{DOMAIN}}.access.log combined + ErrorLog {{LOG_DIR}}/{{DOMAIN}}.error.log + diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..56af89b --- /dev/null +++ b/test.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if diff -u <(USER=nobody DOMAIN=example.com ./templater.sh examples/vhost-php.tpl.conf) examples/vhost-php.conf; then + echo OK +else + echo Differences found + exit 1 +fi From b3871a6e8f4d7c26a78806269c93ee38bbef1011 Mon Sep 17 00:00:00 2001 From: Sebastien Lavoie Date: Tue, 30 Jan 2018 18:36:23 -0800 Subject: [PATCH 06/14] Build status badge --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 828ec14..9eeb4f3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,10 @@ # BASH Templater + Very simple templating system that replace {{VAR}} by $VAR environment value Supports default values by writting {{VAR=value}} in the template +[![Build Status](https://travis-ci.org/lavoiesl/bash-templater.svg?branch=master)](https://travis-ci.org/lavoiesl/bash-templater) + ## Author Sébastien Lavoie From a245cf8ce6b732e0c7f445393f8b39199a0bed2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Lavoie?= Date: Tue, 30 Jan 2018 18:43:55 -0800 Subject: [PATCH 07/14] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9eeb4f3..a62b3ec 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # BASH Templater -Very simple templating system that replace {{VAR}} by $VAR environment value -Supports default values by writting {{VAR=value}} in the template +Very simple templating system that replace `{{VAR}}` by `$VAR` environment value. + +Supports default values by writting `{{VAR=value}}` in the template. [![Build Status](https://travis-ci.org/lavoiesl/bash-templater.svg?branch=master)](https://travis-ci.org/lavoiesl/bash-templater) From 265e91f31affdb2fdc56e011592ba21e1b95ba74 Mon Sep 17 00:00:00 2001 From: Guillermo Calvo Date: Thu, 1 Feb 2018 01:19:41 +0900 Subject: [PATCH 08/14] Allow whitespace inside braces (#3) Modify the example template to incorporate spaces --- examples/vhost-php.tpl.conf | 8 ++++---- templater.sh | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/vhost-php.tpl.conf b/examples/vhost-php.tpl.conf index 682dacf..2e773f7 100644 --- a/examples/vhost-php.tpl.conf +++ b/examples/vhost-php.tpl.conf @@ -7,11 +7,11 @@ ServerAdmin {{EMAIL}} ServerName {{DOMAIN}} - ServerAlias www.{{DOMAIN}} + ServerAlias www.{{ DOMAIN }} DocumentRoot "{{DOC_ROOT}}" - + AllowOverride All Order allow,deny Allow From All @@ -20,9 +20,9 @@ AddHandler php-script .php Action php-script /php5.fastcgi virtual Alias /php5.fastcgi {{FCGI}} - FastCGIExternalServer {{FCGI}} -socket {{SOCKET}} + FastCGIExternalServer {{ FCGI }} -socket {{SOCKET}} LogLevel warn CustomLog {{LOG_DIR}}/{{DOMAIN}}.access.log combined - ErrorLog {{LOG_DIR}}/{{DOMAIN}}.error.log + ErrorLog {{LOG_DIR }}/{{ DOMAIN}}.error.log diff --git a/templater.sh b/templater.sh index 76e87fd..b6fe194 100755 --- a/templater.sh +++ b/templater.sh @@ -8,7 +8,7 @@ if [[ ! -f "$1" ]]; then fi template="$1" -vars=$(grep -oE '\{\{[A-Za-z0-9_]+\}\}' "$template" | sort | uniq | sed -e 's/^{{//' -e 's/}}$//') +vars=$(grep -oE '\{\{\s*[A-Za-z0-9_]+\s*\}\}' "$template" | sort | uniq | sed -e 's/^{{//' -e 's/}}$//') if [[ -z "$vars" ]]; then echo "Warning: No variable was found in $template, syntax is {{VAR}}" >&2 @@ -87,7 +87,7 @@ for var in $vars; do # Escape slashes value="$(escape_chars "${value}" "\\" '/' ' ')"; replaces+=("-e") - replaces+=("s/{{${var}}}/${value}/g") + replaces+=("s/{{\s*${var}\s*}}/${value}/g") done sed "${replaces[@]}" "${template}" From b10473aab774cd9ebb65c33e8321a4de1181d45e Mon Sep 17 00:00:00 2001 From: Cerem Cem ASLAN Date: Fri, 25 Dec 2020 08:40:24 +0300 Subject: [PATCH 09/14] resolves johanhaleby/bash-templater#10 --- templater.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/templater.sh b/templater.sh index e96f2ff..6e3fe83 100755 --- a/templater.sh +++ b/templater.sh @@ -34,6 +34,7 @@ readonly PROGNAME=$(basename $0) config_file="" print_only="false" silent="false" +nounset="false" usage="${PROGNAME} [-h] [-d] [-f] [-s] -- @@ -46,6 +47,8 @@ where: Specify a file to read variables from -s, --silent Don't print warning messages (for example if no variables are found) + -u, --nounset + Unset variables throws error instead of a warning examples: VAR1=Something VAR2=1.2.3 ${PROGNAME} test.txt @@ -82,6 +85,9 @@ if [ "$#" -ne 0 ]; then -s|--silent) silent="true" ;; + -u|--nounset) + nounset="true" + ;; --) break ;; @@ -156,7 +162,12 @@ for var in $vars; do value=$(var_value $var | sed -e "s;\&;\\\&;g" -e "s;\ ;\\\ ;g") # '&' and is escaped if [[ -z "$value" ]]; then if [ $silent == "false" ]; then - echo "Warning: $var is not defined and no default is set, replacing by empty" >&2 + if [[ $nounset == "false" ]]; then + echo "Warning: $var is not defined and no default is set, replacing by empty" >&2 + else + echo "ERROR: $var is not defined and no default is set." >&2 + exit 1 + fi fi fi From c38728bc3cd660d5a8f0a72b8fef415ecd54d184 Mon Sep 17 00:00:00 2001 From: Cerem Cem ASLAN Date: Fri, 25 Dec 2020 09:22:44 +0300 Subject: [PATCH 10/14] resolves johanhaleby/bash-templater#12 --- templater.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/templater.sh b/templater.sh index b3a8384..6c0153b 100755 --- a/templater.sh +++ b/templater.sh @@ -60,13 +60,6 @@ if [ $# -eq 0 ]; then exit 1 fi -if [[ ! -f "${1}" ]]; then - echo "You need to specify a template file" >&2 - echo "$usage" - exit 1 -fi - -template="${1}" if [ "$#" -ne 0 ]; then while [ "$#" -gt 0 ] @@ -79,8 +72,8 @@ if [ "$#" -ne 0 ]; then -p|--print) print_only="true" ;; - -f|--file) - config_file="$2" + -f|--file) shift + config_file="$1" ;; -s|--silent) silent="true" @@ -88,20 +81,27 @@ if [ "$#" -ne 0 ]; then -u|--nounset) nounset="true" ;; - --) - break - ;; -*) echo "Invalid option '$1'. Use --help to see the valid options" >&2 exit 1 ;; - # an option argument, continue - *) ;; + # an option argument, this must be the template + *) + template="$1" + ;; esac shift done fi +if [[ ! -f "$template" ]]; then + echo "You need to specify a template file" >&2 + echo "$usage" + exit 1 +fi + + + vars=$(grep -oE '\{\{\s*[A-Za-z0-9_]+\s*\}\}' "$template" | sort | uniq | sed -e 's/^{{//' -e 's/}}$//') if [[ -z "$vars" ]]; then From 18438130ef7624d00669e7c9e187f6b5c4e3bd99 Mon Sep 17 00:00:00 2001 From: Cerem Cem ASLAN Date: Fri, 25 Dec 2020 12:04:20 +0300 Subject: [PATCH 11/14] fixed --nounset handling --nounset will make the templater.sh throw error regardless of -s (silent) switch. --- templater.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/templater.sh b/templater.sh index 6c0153b..522e3be 100755 --- a/templater.sh +++ b/templater.sh @@ -189,13 +189,11 @@ fi for var in $vars; do value=$(var_value $var | sed -e "s;\&;\\\&;g" -e "s;\ ;\\\ ;g") # '&' and is escaped if [[ -z "$value" ]]; then - if [ $silent == "false" ]; then - if [[ $nounset == "false" ]]; then - echo "Warning: $var is not defined and no default is set, replacing by empty" >&2 - else - echo "ERROR: $var is not defined and no default is set." >&2 - exit 1 - fi + if [[ $nounset == "false" ]]; then + [ $silent == "true" ] || echo "Warning: $var is not defined and no default is set, replacing by empty" >&2 + else + echo "ERROR: $var is not defined and no default is set." >&2 + exit 1 fi fi From 6e6803e31c556b4c708a492d136298ccf2d6b235 Mon Sep 17 00:00:00 2001 From: Cerem Cem ASLAN Date: Fri, 25 Dec 2020 12:07:28 +0300 Subject: [PATCH 12/14] fixed no-variable-template handling. --- templater.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templater.sh b/templater.sh index 522e3be..013d18b 100755 --- a/templater.sh +++ b/templater.sh @@ -106,8 +106,10 @@ vars=$(grep -oE '\{\{\s*[A-Za-z0-9_]+\s*\}\}' "$template" | sort | uniq | sed -e if [[ -z "$vars" ]]; then if [ "$silent" == "false" ]; then - echo "Warning: No variable was found in ${template}, syntax is {{VAR}}" >&2 + echo "Warning: No variable was found in ${template}" >&2 fi + cat $template + exit 0 fi # Load variables from file if needed From 659cee80a1c5fa3c2186272e43fd997d44c9ff62 Mon Sep 17 00:00:00 2001 From: Cerem Cem ASLAN Date: Fri, 25 Dec 2020 16:18:24 +0300 Subject: [PATCH 13/14] added "--verbose" switch for a clearer output --- templater.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/templater.sh b/templater.sh index 013d18b..17e154c 100755 --- a/templater.sh +++ b/templater.sh @@ -35,6 +35,7 @@ config_file="" print_only="false" silent="false" nounset="false" +verbose="false" usage="${PROGNAME} [-h] [-d] [-f] [-s] -- @@ -49,6 +50,8 @@ where: Don't print warning messages (for example if no variables are found) -u, --nounset Unset variables throws error instead of a warning + -v, --verbose + Verbose output examples: VAR1=Something VAR2=1.2.3 ${PROGNAME} test.txt @@ -81,6 +84,9 @@ if [ "$#" -ne 0 ]; then -u|--nounset) nounset="true" ;; + -v|--verbose) + verbose="true" + ;; -*) echo "Invalid option '$1'. Use --help to see the valid options" >&2 exit 1 @@ -105,7 +111,7 @@ fi vars=$(grep -oE '\{\{\s*[A-Za-z0-9_]+\s*\}\}' "$template" | sort | uniq | sed -e 's/^{{//' -e 's/}}$//') if [[ -z "$vars" ]]; then - if [ "$silent" == "false" ]; then + if [ "$verbose" == "true" ]; then echo "Warning: No variable was found in ${template}" >&2 fi cat $template From da62a997f7ac596e0b7c0be76c9b2f8ad616cc2d Mon Sep 17 00:00:00 2001 From: Cerem Cem ASLAN Date: Thu, 7 Jan 2021 13:58:18 +0300 Subject: [PATCH 14/14] working directory of config file is now its own dir Relative paths can be used in config file. --- templater.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templater.sh b/templater.sh index 17e154c..af11b00 100755 --- a/templater.sh +++ b/templater.sh @@ -125,8 +125,10 @@ if [ "${config_file}" != "" ]; then echo "$usage" exit 1 fi - + _pwd=$PWD + cd "$(dirname "$config_file")" source "${config_file}" + cd "$_pwd" fi var_value() {