NotionCommotion |
04-12-2014 05:00 PM |
Using cat to create a file which contain variables
I thought I would be smart, and instead of using vim to create a file, I would use the following:
Code:
cat > /etc/yum.repos.d/PUIAS_6_computational.repo <<EoT
[PUIAS_6_computational]
name=PUIAS computational Base $releasever - $basearch
mirrorlist=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch/mirrorlist
#baseurl=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch
enabled=1
priority=90
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puias
EoT
But when I looked at the file I created, I saw the following:
Code:
[root@desktop ~]# cat /etc/yum.repos.d/PUIAS_6_computational.repo
[PUIAS_6_computational]
name=PUIAS computational Base -
mirrorlist=http://puias.math.ias.edu/data/puias/computational///mirrorlist
#baseurl=http://puias.math.ias.edu/data/puias/computational//
enabled=1
priority=90
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puias
[root@desktop ~]#
So, I learned something. cat interprets anything that starts with a dollar sign ($) as a variable, and attempts to resolve it. Just on a hunch, I tried escaping the dollar signs using a backslash (\), and found it did the trick.
Two questions. Did I solve this issue correctly? Is this common to many Linux commands or just cat?
Thanks
|