I have this:
cat > ~/add_api_txt_hook.sh <<EOF
#!/bin/bash
...
echo $MY_ENV_VAR
EOF
MY_ENV_VAR is not set when this file is made. So it makes it "" in the file.
I want the file contents to be
#!/bin/bash
...
echo $MY_ENV_VAR
NOT:
#!/bin/bash
...
echo ""
How do I print the actual ENV VAR KEY to the file? I have searched the internet, but it only returns how to print the value to the file.
Tried google and various syntax around the key (), "", {} etc...
There are several ways to accomplish this.
Obviously, as SiKing pointed out, you can just backslash-escape the dollar sign.
You can also quote the
EOFitself. Whileputs the value of
$PATH(including being empty, as in your case) in the file,does not:
Likewise, you can use a "here-string":
But be aware that where a here-doc behaves much the same whether single- or double-quotes are used -
here-strings differentiate; single-quotes don't expand variables, but doubles do.