zoukankan      html  css  js  c++  java
  • 安装jdk1.8

    这是很普通的shell的脚本,只需要注意:echo 语句内出现的变量,需要转义!

    #!/bin/bash

    function get_current_time_stamp()
    {
    echo `date "+%Y/%m/%d %H:%M:%S"`
    }

    function send_error()
    {
    echo -e "e[1;45m [ Error ] `get_current_time_stamp` - $1 -e[0m"
    }

    function send_success()
    {
    echo -e "e[1;32m [ Success ] `get_current_time_stamp` - $1 -e[0m"
    }

    function send_info()
    {
    echo -e "e[1;34m [ Info ] `get_current_time_stamp` - $1 -e[0m"
    }

    function send_warn()
    {
    echo -e "e[1;33m [ Warn ] `get_current_time_stamp` - $1 -e[0m"
    }

    check_java=$(rpm -qa|grep -E "^java" | wc -l)

    if [ $check_java -gt 0 ];then
    send_error "java has been installed, exit..."
    exit 1
    fi

    if [ ! -d /usr/local ];then
    mkdir -p /usr/local
    chmod 755 /usr/local
    fi

    if [ ! -e "./jdk-8u181-linux-x64.tar.gz" ];then
    send_error "jdk package not found..."
    exit 1
    fi

    tar -zxvf ./jdk-8u181-linux-x64.tar.gz -C /usr/local/

    if [ $? -ne 0 ];then
    send_error "tar error, Please Check!"
    exit 1
    fi

    cp /etc/profile /etc/profile.bak

    echo "JAVA_HOME=/usr/local/jdk1.8.0_181" >> /etc/profile
    echo "JRE_HOME=$JAVA_HOME/jre" >> /etc/profile
    echo "PATH=$PATH:$JAVA_HOME/bin" >> /etc/profile
    echo "CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar" >> /etc/profile

    echo "export JAVA_HOME" >> /etc/profile
    echo "export JRE_HOME" >> /etc/profile
    echo "export PATH" >> /etc/profile
    echo "export CLASSPATH" >> /etc/profile

    send_info "JDK install finished."

  • 相关阅读:
    python基础语法
    java关键字之final
    汉字占几个字节?
    Java学习记录(补充二:面对对象基础复习,习题)
    Java学习记录(补充二)
    Java学习记录(补充一(以习题为主:判断,循环语句))
    Java学习记录
    JS学习记录(jQuery补充一)
    JS学习记录(jQuery)
    JS学习记录(数组补充一)
  • 原文地址:https://www.cnblogs.com/ralphdc/p/9348162.html
Copyright © 2011-2022 走看看