I am trying to add a YUM repo from the command line like so
cat > /etc/yum.repos.d/my_stable_repo.repo << EOF
[my_stable_repo]
name=Stable Repo
baseurl='https://myurl/$releasever/stable/Packages/'
enabled=1
gpgcheck=0
EOF
However, when I do it this way and I take a look at /etc/yum.repos.d/my_stable_repo.repo
, I do not see $releasever
in the URL. Instead, /etc/yum.repos.d/my_stable_repo.repo
looks like:
[my_stable_repo]
name=Stable Repo
baseurl='https://myurl//stable/Packages/'
enabled=1
gpgcheck=0
Notice that the releasever variable was deleted. I am assuming that this is because when I run the command to write the contents to the file from the shell, linux is evaluating the $releasever
variable against the global environment, seeing that is empty, and replacing it with an empty string.
But I actually want just the string $releasever
to be in /etc/yum.repos.d/my_stable_repo.repo
. So the file should look like this the below instead:
[my_stable_repo]
name=Stable Repo
baseurl='https://myurl/$releasever/stable/Packages/'
enabled=1
gpgcheck=0
How can I write the file out like this with the $releasever
in plain text from the shell?
TLDR: How can I write a string that looks like it has a variable in it (i.e. $releasever
) to a file from the command line without actually evaluating the variable?
To prevent Bash from interpreting the dollar sign in your cat
command, simply put the first EOF in single quotes like so:
cat > /etc/yum.repos.d/my_stable_repo.repo << 'EOF'
[my_stable_repo]
name=Stable Repo
baseurl='https://myurl/$releasever/stable/Packages/'
enabled=1
gpgcheck=0
EOF