[Share Experiences] 发一个在脚本中使用环境变量的帖子
Tofloor
poster avatar
酷谷的谷子
deepin
2023-07-02 01:24
Author

有时候我们在脚本中可能需要使用一个指定版的Nginx Python Java 其实很简单

这样做的目的就是 不影响系统本身的环境变量

优先级就是脚本内置的高于系统内置的,只对于该脚本有效。

系统内置的,对全局用户有效。 /etc/profile

用户配置的只对当前用户有效 $HOME/.bashrc

export MYnginx='/opt/nginx-1.22.1/sbin'  #MYnginx是变量名称,后面是执行程序路径

export PATH=$MYnginx:$PATH #PATH系统默认的环境变量名称 
#像这样
export PATH=/bin:/sbin:$PATH #每个可执行程序路径 用 ':'使用英文状态下的冒号隔开最后更:$PATH

Nginx

#!/bin/bash
#------------------------------
# 引入指定版本 nginx 环境变量
#------------------------------
export MYnginx='/opt/nginx-1.22.1/sbin'
export PATH=$MYnginx:$PATH
nginx -v

Python

#!/bin/bash
#------------------------------
# 引入指定版本 python3 环境变量
#------------------------------
export MYpython='/opt/Python-3.10.12'
export PATH=$MYpython/bin:$PATH
python3 --version

JAVA

#!/bin/bash
#-------------------
# java环境变量
#-------------------
export JAVA_HOME=/opt/jdk1.8.0_371
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}
java -version
Reply Favorite View the author
All Replies
阿尼樱奈奈
Moderator
2023-07-02 01:30
#1

applaud

Reply View the author
青稚
Moderator
2023-07-02 02:54
#2

like

相信有坛友会用到的。

Reply View the author
ThinKinG
deepin testing team
2023-07-04 23:58
#3

亲!你这个可以创建个WIKIlike

Reply View the author
酷谷的谷子
deepin
2023-07-05 01:02
#4
ThinKinG

亲!你这个可以创建个WIKIlike

怎么创建

Reply View the author
ThinKinG
deepin testing team
2023-07-05 17:16
#5
酷谷的谷子

怎么创建

https://wiki.deepin.org/zh/home

这个是wiki地址

Reply View the author
酷谷的谷子
deepin
2023-07-05 18:22
#6
ThinKinG

https://wiki.deepin.org/zh/home

这个是wiki地址

没有权限

Reply View the author
ThinKinG
deepin testing team
2023-07-05 18:25
#7
酷谷的谷子

没有权限

使用论坛账号不能登录吗

Reply View the author
酷谷的谷子
deepin
2023-07-05 18:42
#8
ThinKinG

使用论坛账号不能登录吗

可以登入但是没有添加内容的权限没有入口,不能像发帖子那样

Reply View the author
ThinKinG
deepin testing team
2023-07-05 18:52
#9
酷谷的谷子

可以登入但是没有添加内容的权限没有入口,不能像发帖子那样

这个添加没有吗
image.png

Reply View the author
酷谷的谷子
deepin
2023-07-05 18:55
#10
ThinKinG

这个添加没有吗
image.png

QQ截图20230705105451.png

Reply View the author