本文的主线 Shell => Profile=> Env
本文环境基于Ubuntu1604 => vagrant up
Shell
echo $SHELL
# /bin/sh
echo $0
# -sh
ls -l /bin/sh
# lrwxrwxrwx 1 root root 4 Feb 18 2016 /bin/sh -> dash
cat /etc/shells
# /bin/sh
# /bin/dash
# /bin/bash
# ...
grep op /etc/passwd
# op:x:1002:1002::/home/op:
sudo usermod --shell /bin/bash op
grep op /etc/passwd
# op:x:1002:1002::/home/op:/bin/bash
- 退出后重新登录
echo $SHELL
# /bin/bash
echo $0
# -bash
bash
echo $SHELL
# /bin/bash
echo $0
# bash
Profile
cat /etc/profile
# $PS1
# /etc/profile.d/*.sh
cat ~/.profile
# $HOME/.bashrc
cat ~/.bashrc
# $PS1
# alias
# PATH
# JAVA_HOME
sudo vim /etc/profile
# TEST="/etc/profile"
vim ~/.profile
# TEST+=":~/.profile"
vim ~/.bashrc
# TEST+=":~/.bashrc"
Env
- 退出后重新登录
echo $TEST
# /etc/profile:~/.bashrc:~/.profile
echo $0
# -bash
bash
echo $TEST
# :~/.bashrc
echo $0
# bash
bash --login
echo $TEST
# /etc/profile:~/.bashrc:~/.profile
echo $0
# bash
login shell | non-login shell | |
---|---|---|
定义 | A login shell is a shell given to a user upon login into their user account. This is initiated by using the -l or --login option, or placing a dash as the initial character of the command name, for example invoking bash as -bash | Non-login shell, also called a sub shell is a shell started after the login process without the -l or --login option and without an extra dash before the command name |
配置 | it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable | bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist |
使用 | Accessing your computer remotely using ssh Simulating an initial login shell with bash -l or sh -l "su -"切换至指定用户的login shell |
其他 |
互动: 执行shell脚本时的TEST值?
vim test.sh
#! /bin/bash
echo $TEST
chmod +x test.sh
./test.sh
网友评论