【263】Linux 添加环境变量 & 全局 shell 脚本
Linux电脑添加环境变量
方法一:通过修改 profile 文件添加环境变量
1. 打开终端,输入【vi /etc/profile】,如下所示,点击回车
[ocean@ygs-jhyang-w1 Linux-Windows]$ vi /etc/profile
2. 从命令模式切换到编辑模式使用“A”、“a”、“O”、“o”、“I”、“i”键。
在最后加入【export PATH="$PATH:/home/ocean/alex/Others/Linux-Windows"】
export PATH="$PATH:/home/ocean/alex/Others/Linux-Windows"
退出编辑模式按ESC,不保存退出按【:q】
退出编辑模式按ESC,保存退出按【:wq】
3. 退出后,执行【source /etc/profile】,可以应用环境变量的修改
[ocean@ygs-jhyang-w1 Linux-Windows]$ source /etc/profile
4. 通过【echo $PATH】 可以查看环境变量
[ocean@ygs-jhyang-w1 Linux-Windows]$ echo $PATH
/usr/sbin:/sbin:/home/ocean/bin:/home/ocean/alex/Others/Linux-Windows
注意:这种方法是针对用户起作用。比如如果是在root权限操作,则root用户有效;如上就是对当前用户起作用。
方法二:通过修改 bashrc 文件添加环境变量
1. 打开终端,在linux系统普通用户目录(cd /home/xxx)或root用户目录(cd /root)下,用指令ls -al可以看到4个隐藏文件,其中包括 .bashrc.
输入【vi .bashrc】,如下所示,点击回车
[ocean@ygs-jhyang-w1 桌面]$ cd /home/ocean
[ocean@ygs-jhyang-w1 ~]$ ls -al
-rw-r--r--. 1 ocean ocean 535 4\u6708 13 15:45 .bashrc
[ocean@ygs-jhyang-w1 ~]$ vi .bashrc
2. 从命令模式切换到编辑模式使用“A”、“a”、“O”、“o”、“I”、“i”键。
在最后加入【export PATH=$PATH:/home/ocean/alex/FileTransfer】
export PATH=$PATH:/home/ocean/alex/FileTransfer
退出编辑模式按ESC,不保存退出按【:q】
退出编辑模式按ESC,保存退出按【:wq】
执行文件
将路径添加为环境变量之后,就可以通过任意位置打开里面的shell文件,可以按照如下执行方式:
[ocean@ygs-jhyang-w1 \u684c\u9762]$ bash z-wx.sh
文件权限修改
通过 chmod 修改权限,将路径设置为环境变量,即可以直接运行
# 直接运行,显示权限不够
[ocean@ygs-jhyang-w1 Others]$ ./b.sh
bash: ./b.sh: 权限不够 # 需要将路径设置为环境变量
[ocean@ygs-jhyang-w1 Others]$ b.sh
bash: b.sh: command not found # 添加执行权限
[ocean@ygs-jhyang-w1 Others]$ chmod a+x b.sh # 可以执行了
[ocean@ygs-jhyang-w1 Others]$ ./b.sh
alex batch_file daydata l.py
alex.tar.gz b.sh daydata1 NC
参考:chmod命令
【263】Linux 添加环境变量 & 全局 shell 脚本的更多相关文章
- Linux 添加环境变量和删除环境变量
环境变量是一个具有特定名字的对象,它包含了一个或者多个应用程序所将使用到的信息.例如PATH.在交叉编译中,会经常运用到环境变量的设置. 在linux中,查看当前全部的环境变量的命令式env. 当然也 ...
- 【Linux】 环境变量与shell配置&执行
■ 变量与环境变量 shell环境通常存在很多变量,变量可以通过echo $VAR或${VAR}的方式查看.set命令可以查看当前环境中的所有变量(包括一般的自定义变量和环境变量) 变量的设置通过简单 ...
- Linux添加环境变量与GCC编译器添加INCLUDE与LIB环境变量
对所有用户有效在/etc/profile增加以下内容.只对当前用户有效在Home目录下的.bashrc或.bash_profile里增加下面的内容:(注意:等号前面不要加空格,否则可能出现 comma ...
- linux添加环境变量
修改 /当前用户/.bash_profile文件,修改export PATH,添加自己的可执行程序的目录即可 例如: /root/.bash_profile export PATH=$PATH:/u ...
- linux添加环境变量(centos)
1.查看当前环境变量 #echo $PATH 2.增加环境变量 #vi /etc/profile export PATH=/usr/path/bin:$PATH 3.生效 #source /etc/p ...
- linux 添加环境变量(php为例)
find / -name php vim /etc/profile 文件最后添加 export PATH=$PATH:/usr/local/php/bin source /etc/profile p ...
- linux添加环境变量(path)
分为三步 1.sudo vim /etc/profile 2.export PATH="全路径:$PATH" 3.source /etc/profile 我的微信二维码如下,欢迎交 ...
- linux 添加环境变量
You have to edit three files to set a permanent environment variable as follow: ~/.bashrc When you o ...
- linux命令(11)环境变量:查看和添加环境变量
linux 环境变量系统: 系统级别:/etc/profile./etc/bashrc/ ./etc/environment 用户级别:~/.profile.~/.bashrc. ~/.bash_pr ...
随机推荐
- Spring Boot入门——邮件发送
1.引入依赖 <!-- mail依赖 --> <dependency> <groupId>org.springframework.boot</groupId& ...
- Composer如何安装(安装注意事项)
Composer如何安装(安装注意事项) 一.总结 一句话总结:安装的时候主要看安装错误提示: 常见的错误有: a.php需要开启openssl配置.我们打开php目录下的php.ini.将opens ...
- SQL Server 性能优化之RML Utilities:快速入门(Quick Start)(1)
SQL Server 性能优化之RML Utilities:快速入门(Quick Start)(1) 安装Quick Start工具 RML(Replay Markup Language)是MS ...
- map和reduce 个数的设定 (Hive优化)经典
一. 控制hive任务中的map数: 1. 通常情况下,作业会通过input的目录产生一个或者多个map任务. 主要的决定因素有: input的文件总个数,input的文件大小,集群设置 ...
- pandas 中文快速查询手册
本文翻译自文章: Pandas Cheat Sheet - Python for Data Science ,同时添加了部分注解. 对于数据科学家,无论是数据分析还是数据挖掘来说,Pandas是一个非 ...
- 15 Python 迭代器和生成器
什么是迭代 (iterable) 字符串.列表.元组.字典.集合都可以被for循环,说明他们都是可迭代的. 可以直接作用于for循环的对象统称为可迭代对象(Iterable). 可以被next()函数 ...
- Eclipse插件开发_学习_02_GEF入门实例
一.前言 这一节,我们将会创建一个GEF入门实例 二.新建RCP项目 1. New 一个 Plug-in Project 2.输入项目名 项目名:com.ray.gef.helloworld 3.Co ...
- Oracle 11g 客户端连接 oracle 10g 服务端,乱码问题
从网上搜索资料基本确定:字符集错误 Pl/sql 连接到oracle 数据库 “select userenv('language') from dual” 找到服务端的对应的字符集,拷贝之: 到本 ...
- XE7 UTF8Encode
之前用D7写的客户端程序升级到XE7,服务端依旧用D7.使用TIdHTTP控件 Get(URL)方法,服务端(TIdHttpServer)收到的中文字符解释成乱码. 鼓捣了一会,这么搞定的: 1. 客 ...
- java中获取各种上下文路径的方法小结
一.获得都是当前运行文件在服务器上的绝对路径在servlet里用:this.getServletContext().getRealPath(); 在struts用:this.getServlet(). ...