BASH script pass variables without replacement to a new script

As part of the script system build, I have a script that creates various files and configurations.

However, one part of the script assembly creates a new script that contains variables that I do not want to allow when the script assembly starts. Code snippet example

cat - > /etc/profile.d/mymotd.sh <<EOF hostname=`uname -n` echo -e "Hostname is $hostname" EOF 

I tried all kinds of combinations of 'and' and (and [but I can’t get a script to send content without substituting values ​​and placing substitutes in the new script, and not in the source text.

Ideas?

+6
source share
2 answers

The easiest way, assuming that you do not want something to be replaced in this document, is to put the EOF marker in quotation marks, for example:

 cat - > /etc/profile.d/mymotd.sh <<'EOF' hostname=`uname -n` echo -e "Hostname is $hostname" EOF 
+23
source

The easiest way to avoid $

echo -e "Hostname is \ $ hostname"

+9
source

Source: https://habr.com/ru/post/898030/


All Articles