CentOS更新163 yum源

这个脚本也没啥多大意义,只是为了自己练习着写一下bash

=====================================================================================

#!/bin/bash

# Backup CentOS-Base.repo 备份原来的源

pushd /etc/yum.repos.d/

a=/etc/yum.repos.d/CentOS-Base.repo 将文件的路径值赋给变量,然后判断这个文件是否存在

#判断的语句还用的不是很熟,这里纠结了一下,开始用的是$1=/etc/yum.repos.d/CentOS-Base.repo

#结果报错,

if [ -e "$a" ]; then

    echo line 4 is executed...

    sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

    pwd

else

    echo CentOS-Base.repo is not exist...

fi

cd /etc/yum.repos.d/

# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

# wget is not installed yet

sudo curl -O http://mirrors.163.com/.help/CentOS6-Base-163.repo

# curl参数要带-O才是下载文件,而且文件以网站原来的名字为下载

b=CentOS6-Base-163.repo

if [ -e "$b" ]; then

cp CentOS6-Base-163.repo CentOS-Base.repo

#前面都用了两个sudo而这里却没有用sudo,所以感觉还是都不要用了直接在执行的时候用sudo

    yum clean all

    yum makecache

    echo The 163 yum is updated...

else

    echo /etc/yum.repos.d/CentOS-Base.repo is not exist...

fi

pushd

=====================================================================================

这算是自己写的第一个bash小脚本,学的不好还要继续下去

你可能感兴趣的:(CentOS更新163 yum源)