linux 非登录shell自动,Linux登录shell和非登录(交互式shell)环境变量配置
使用Jenkins执行shell脚本的时候, 碰到command not found. 比如java mvn, 这些环境变量配置在/etc/profile
中, 但jenkins执行的时候并没有加载.
这是因为jenkins执行的shell是非登录交互式shell, 并不会加载/etc/profile.
交互式shell会加载.bashrc, 进而会加载/etc/bashrc, 而/etc/bashrc会加载/etc/profile.d/*.sh.
因此, 自定义的变量应该定义在/etc/profile.d/*.sh
1.登录shell
所谓登录shell,指的是当用户登录系统时所取的那个shell,登录shell属于交互式shell。
登录shell将查找4个不同的启动文件来处理其中的命令。 bash shell处理文件的顺序如下:
1:/etc/profile
2:/etc/profile.d等待配置文件
3:$HOME/.bash_profile 会加载$HOME/.bashrc和/etc/bashrc
4:$HOME/.bash_login
5:$HOME/.profile
2. 交互式非登录shell
如果启动了一个bash shell而没有登入系统(如在CLI提示符中键入bash),
则启动了一个交互式非登录shell.
$HOME/.bashrc
交互式非登录shell执行~/.bashrc文件中的命令.在每次执行shell脚本时,都会重新读取这个文件,所以是最完整的。
但是万事都不是一样的,debain系列的是不同的,如ubuntu
/etc/profile–>/etc/environment–>$HOME/.profile.要配置java等变量时,都/etc/environment中
.bashrc
# .bashrc
# User specific aliases and functions
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
登录shell的初始化文件(比如.bash_profile)通常会运行这个文件。这样,登录shell和非登录shell都可以使用.bashrc中的命令。
/etc/bashrc
[root@localhost ~]# cat /etc/bashrc
# /etc/bashrc
# System wide functions and aliases
# Environment stuff goes in /etc/profile
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
# are we an interactive shell?
if [ "$PS1" ]; then
if [ -z "$PROMPT_COMMAND" ]; then
case $TERM in
xterm*|vte*)
if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
elif [ "${VTE_VERSION:-0}" -ge 3405 ]; then
PROMPT_COMMAND="__vte_prompt_command"
else
PROMPT_COMMAND='printf " 33]0;%s@%s:%s 07" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
fi
;;
screen*)
if [ -e /etc/sysconfig/bash-prompt-screen ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
else
PROMPT_COMMAND='printf " 33k%s@%s:%s 33\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
fi
;;
*)
[ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
;;
esac
fi
# Turn on parallel history
shopt -s histappend
history -a
# Turn on checkwinsize
shopt -s checkwinsize
[ "$PS1" = "\s-\v\$ " ] && PS1="[u@h W]\$ "
# You might want to have e.g. tty in prompt (e.g. more virtual machines)
# and console windows
# If you want to do so, just add e.g.
# if [ "$PS1" ]; then
# PS1="[u@h:l W]\$ "
# fi
# to your custom modification shell script in /etc/profile.d/ directory
fi
if ! shopt -q login_shell ; then # We're not a login shell
# Need to redefine pathmunge, it get's undefined at the end of /etc/profile
pathmunge () {
case ":${PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
}
# By default, we want umask to get set. This sets it for non-login shell.
# Current threshold for system reserved uid/gids is 200
# You could check uidgid reservation validity in
# /usr/share/doc/setup-*/uidgid file
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
umask 002
else
umask 022
fi
SHELL=/bin/bash
# Only display echos from profile.d scripts if we are no login shell
# and interactive - otherwise just process them to set envvars
for i in /etc/profile.d/*.sh; do
if [ -r "$i" ]; then
if [ "$PS1" ]; then
. "$i"
else
. "$i" >/dev/null
fi
fi
done
unset i
unset -f pathmunge
fi
# vim:ts=4:sw=4
参考
linux 非登录shell自动,Linux登录shell和非登录(交互式shell)环境变量配置相关推荐
- wget oracle安装包,linux下wget方式直接下载jdk1.8.rpm格式安装包及环境变量配置
文章参考自:链接 前言:由于版权原因,Linux发行版并没有包含官方版的Oracle JDK,必须自己从官网上下载安装.Oracle官网用Cookie限制下载方式,使得眼下只能用浏览器进行下载,使用其 ...
- 1.非关系型数据库(Nosql)之mongodb:mongodb的安装,环境变量配置,数据库服务端启动,客户端启动
1.MongoDB官方网站上下载MongoDB的安装版本.截图如下: 2 安装64位版本的mongodb.将它解压到: E:\Installed\mongodb-win32-x86_64-2.6 ...
- 【Linux】《Linux命令行与shell脚本编程大全 (第4版) 》笔记-Chapter6-Linux 环境变量
六.Linux 环境变量 bash shell 使用环境变量来存储 shell 会话和工作环境的相关信息(这也是被称作环境变量的原因).环境变量允许在内存中存储数据, 以便 shell 中运行的程序或 ...
- Linux环境变量配置的三个方法--/etc/profile,~/.bashrc,shell
[环境配置的原因] 在windows系统下,很多软件的安装都需要设置环境变量,比如安装JAVA JDK.如果不安装环境变量,在非软件安装的目录下运行javac命令,将会报告"找不到文件&qu ...
- Linux环境变量配置出错,导致登录不了......
Linux环境变量配置出错导致的后果: 1.登陆不了 linux 了 2.基本命令全失效了(如:ls,vi,sudo,su,find,cp等),除了cd命令可用. 解决方法有如下三步: 1.从图形登陆 ...
- Linux下环境变量配置方法梳理(.bash_profile和.bashrc的区别)
博客园 首页 新随笔 联系 管理 订阅 <div class="blogStats"><!--done--> 随笔- 556 文章- 38 评论- 77 ...
- 超详干货!Linux 环境变量配置全攻略
点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 本文转自|机器学习实验室 Linux环境变量配置 在自定义安装软件 ...
- linux环境变量配置的方法,Linux环境变量配置方法
Linux上环境变量配置分为设置永久变量和临时变量两种.环境变量设置方法同时要考虑环境Shell类型,不同类型的SHELL设置临时变量方法和设置永久变量对应的配置文件不同.Linux环境变量本身配置过 ...
- Linux环境变量配置
这篇文章主要介绍了Linux环境变量配置全攻略,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧. 在自定义安装软件的时候,经常需要 ...
- 中修改环境变量_超详干货!Linux环境变量配置全攻略
Linux环境变量配置 在自定义安装软件的时候,经常需要配置环境变量,下面列举出各种对环境变量的配置方法. 下面所有例子的环境说明如下: 系统:Ubuntu 14.0 用户名:uusama 需要配置M ...
最新文章
- SQL Server 插入含有中文字符串出现乱码现象的解决办法
- python好不好用_python应用情况怎么样?是否真的值得学习?
- UIScrollView 的代理方法简单注解
- 使用maven运行单元測试总结
- html日期横向拖动选择控件,一个简单横向javascript日期控件
- linux vscode配置HBuilderX雅蓝主题
- android 判断手机为小米
- SpringMVC的请求-文件上传-单文件上传的代码实现2
- Windows7 IIS7.5 HTTP Error 503 The service is unavailable 另类解决方案
- JS中ptototype和__proto__的关系
- 常用的开始→运行→输入命令集锦
- c语言 枚举类型 uint32_浅谈C语言枚举类型 | 附自创用法分享
- 数据3分钟丨​PingCAP DevCon 2021回顾;openGauss社区颁发首张OGCA认证证书
- 分光计游标盘ab两个游标作用_汽车防撞梁的作用究竟有多大?没有后防撞梁的汽车真的不安全吗?...
- linux下imp导入oracle数据库,Oracle数据库Linux下的导入IMP
- docker的源配置
- 好看的个人网站源码_CMS建站,asp cms,cms系统,cms源码,内容管理系统 - 下载列表
- 修改devcpp5.11的语言选项
- 2020-10-22
- 爬取静态壁纸网站实现批量下载