0

I'm having a BASH script:

#!/usr/bin/env bash

PATH=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)

YAML=$(envsubst < ${PATH}/test.yml)

echo "${YAML}"

It results:

./test.sh: line 5: envsubst: command not found

I see that having a variable inside command substitution causes such error. If I'm not using any:

YAML=$(envsubst < ./test.yml)

Then I'm having an expected successful script execution.

I've tried different syntax using quotes all over the place, but nothing helped.

How do I successfully use variable inside command substitution?

Bash version:

GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu)

UPDATE: A duplicate question. Found an answer here: https://stackoverflow.com/a/5642584/5935309

lllypa
  • 233
  • 1
  • 10

1 Answers1

3

The problem is that you are changing PATH, which is used by Bash internally to define where to look for programs (and in which order).

You changed PATH to only contain the current working dir, and that's not where envsubst is located.

The solution is to use something different than PATH, like FILE_PATH.

Arjan
  • 9,784
  • 1
  • 31
  • 41