IF 语句配置yum源
时间: 2023-11-02 20:59:03 浏览: 38
可以使用以下的 IF 语句来配置 yum 源:
```shell
if [ -f /etc/yum.repos.d/repo_file.repo ]; then
echo "Yum repo file exists!"
else
echo "Yum repo file does not exist!"
# 添加 yum 源配置到 /etc/yum.repos.d/repo_file.repo
cat <<EOL > /etc/yum.repos.d/repo_file.repo
[repo_name]
baseurl=http://yum.example.com/repo/
enabled=1
gpgcheck=0
EOL
echo "Yum repo file created!"
fi
```
在上面的示例中,我们首先使用 `-f` 参数检查 `/etc/yum.repos.d/repo_file.repo` 文件是否存在。如果文件存在,则输出 "Yum repo file exists!",否则输出 "Yum repo file does not exist!"。然后,我们使用 `cat <<EOL > /etc/yum.repos.d/repo_file.repo` 命令将 yum 源配置添加到 `/etc/yum.repos.d/repo_file.repo` 文件中,并输出 "Yum repo file created!"。
你可以将 `baseurl` 替换为你要使用的 yum 源的 URL。确保根据需要进行其他配置更改,如 `enabled` 和 `gpgcheck`。