Shell脚本配置JDK

Posted at — 2020-11-21

起因

某天闲得无聊,自己写了个shell脚本配置JDK

代码如下

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/bin/bash
local_path=$(cd `dirname $0`;pwd)
gz=$(find ./ -name "jdk*.gz")
gz=${gz##*/}
tar -zxf ${gz}
dictory=$(find ./ -maxdepth 1 -type d -name "jdk*")
dictory=${dictory##*/}
JAVA_HOME=${local_path}/${dictory}
echo export JAVA_HOME=${JAVA_HOME} >> /etc/profile
echo export CLASSPATH=.:${JAVA_HOME}/lib >> /etc/profile
echo export PATH=${JAVA_HOME}/bin:${PATH} >> /etc/profile
echo 'HISTTIMEFORMAT="%F %T `whoami` "' >> /etc/profile
reboot