8.3-Shell脚本编程基础-案例分析(三)

1.让所有用户的PATH环境变量的值多出一个路径,例如:/usr/local/apache/bin

[root@localhost data]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin   
[root@localhost data]# echo "PATH=$PATH:/usr/local/apache/bin">>/etc/profile.d/path.sh
[root@localhost data]# vim /etc/profile.d/env.sh
[root@localhost data]# source /etc/profile.d/env.sh 
[root@localhost data]# echo $PATH
/usr/local/apache/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

2.用户 root 登录时,将命令指示符变成红色,并自动启用如下别名:

rm=‘rm –i’

cdnet=‘cd /etc/sysconfig/network-scripts/’

editnet=‘vim /etc/sysconfig/network-scripts/ifcfg-eth0’

editnet=‘vim /etc/sysconfig/network-scripts/ifcfg-eno16777736 或

ifcfg-ens33 ’ (如果系统是CentOS7)

在 ~/.bashrc中将放入以下命令:
PS1='\[\e[1;31m\][\u@\h \w]\$\[\e[0m\]'
alias rm='rm –i'
alias cdnet='cd /etc/sysconfig/network-scripts/'
alias editnet='vim /etc/sysconfig/network-scripts/ifcfg-eth0'
alias editnet='vim /etc/sysconfig/network-scriptsifcfg-ens33'
[root@localhost ~]#cd /etc/sysconfig/network-scripts/
[root@localhost /etc/sysconfig/network-scripts]#cd ..
[root@localhost /etc/sysconfig]#cd ..
[root@localhost /etc]#cd ..
[root@localhost /]#cdnet
[root@localhost /etc/sysconfig/network-scripts]#

3.任意用户登录系统时,显示红色字体的警示提醒信息“Hi,dangerous!”

在/etc/profile.d/env.sh 中添加
echo -e "\e[1;31mHi,dangerous ! \e[0m"

4.编写生成脚本基本格式的脚本,包括作者,联系方式,版本,时间,描述等

5.编写用户的环境初始化脚本reset.sh,包括别名,登录提示符, vim的设置,环境变量等

[root@localhost ~]#cat .bashrc 
# .bashrc

# User specific aliases and functions

PS1='\[\e[1;31m\][\u@\h \w]\$\[\e[0m\]'
alias rm='rm ?i'
alias cdnet='cd /etc/sysconfig/network-scripts/'
alias editnet='vim /etc/sysconfig/network-scripts/ifcfg-eth0'
alias editnet='vim /etc/sysconfig/network-scriptsifcfg-ens33'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi
[root@localhost ~]#cat .vimrc 
set ignorecase
set cursorline
set ts=4
set autoindent
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
if expand("%:e") == 'sh'
 call setline(1,"#!/bin/bash")
 call setline(2,"#********************************************************************")
 call setline(3,"#Author: Kevin.Wen")
 call setline(4,"#Revision: 1.0")
 call setline(5,"#QQ: ????")
 call setline(6,"#Date: ".strftime("%Y-%m-%d"))
 call setline(7,"#FileName: ".expand("%")) 
 call setline(8,"#********************************************************************")
 call setline(9,"")
endif
endfunc
autocmd BufNewFile * normal G
posted @ 2020-08-13 16:31  人生值得  阅读(156)  评论(0编辑  收藏  举报