bashshellenvsubst

is there an escape character for envsubst?


Is there a way to prevent envsubst from substituting a $VARIABLE? For example, I would expect something like:

export THIS=THAT
echo "dont substitute \\\$THIS" | envsubst

and have it return

dont substitute $THIS

but instead I get

dont substitute \THAT

is there any escape character for doing this?


Solution

  • export DOLLAR='$'
    
    export THIS=THAT
    echo '${DOLLAR}THIS' | envsubst
    

    Or more clear:

    export THIS=THAT
    echo '${DOLLAR}THIS' | DOLLAR='$' envsubst