一个shell脚本,让你的linux命令行酷炫起来
可调用如下函数达到echo出来带颜色的文字。。 _echo_error() { echo -ne "\033[31;1m $1\033[0m\n";} _echo_ok() { echo -ne "\033[32;1m $1\033[0m\n";} _echo_warn() { echo -ne "\033[33;1m $1\033[0m\n";} ps aux|awk 'NR==1 {print $2}' ###NR==1 表示第一行第几列 #!/bin/bash # This program is to modify showed marked # PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin echo "########execute $0 begin...##############" SYSVER=$(head -n 1 /etc/issue |awk '{print $3}') function modify_bashrc(){ echo "DST=$(NETCARD=$( ifconfig |grep -B1 192.168 |awk '/eth/ {if ($1=="eth1") print "eth1"; else print "eth0"}' |head -1) ;ifconfig |awk '{if(a) {split($0,b,"addr:| Bcast:");print b[2]} ;a=0}/'"$NETCARD"'/{a=1}' |head -1)" sed -i -e"/PS1/ s#PS1=\"\[.*\\\.*\]#PS1=\"\\\[\\\e\[1;32m\\\]\[\\\u\@\\\[\\\e\[m\\\]\\\[\\\e\[1;36m\\\]\$\(NETCARD=\$\(ifconfig \|grep -B1 192.168 \|awk \'/eth/ \{if \(\$1==\"eth1\"\) print \"eth1\"\; else print \"eth0\"\}\' \|head -1\) \;ifconfig \|awk \'\{if\(a\) \{split\(\$0\,b\,\"addr\:\| Bcast\:\")\;print b\[2\]\} \;a=0\}/\'\"\$NETCARD\"\'/\{a=1\}\' \|head -1\)\\\[\\\e\[m\\\]\\\[\\\e\[1;32m\\\] \\\w\]\\\[\\\e\[m\\\]# " /etc/bashrc sed -i "s/PROMPT_COMMAND='echo/PROMPT_COMMAND=''; #'echo/" /etc/bashrc } case $SYSVER in 4.6) echo "The current system VER $SYSVER" modify_bashrc ;; 5.4) echo "The current system VER $SYSVER" modify_bashrc ;; *) echo "The current system don't know $SYSVER" modify_bashrc ;; esac echo "########execute $0 end...##############"