美文网首页
实用的Shell(二)

实用的Shell(二)

作者: 诺之林 | 来源:发表于2021-01-10 22:46 被阅读0次

本文的主线 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

参考

相关文章

  • 实用的Shell(二)

    本文的主线 Shell => Profile=> Env 本文环境基于Ubuntu1604[http://git....

  • 实用shell

    查看文件件大小

  • shell编程1.1: 初步认识

    1. 如何执行shell脚本 每个shell脚本第一行一般是#! /bin/bash,代表其实用的shell解释器...

  • 日常

    vim SHELL Python Pycharm Pip Virtualenv Github Chrome实用插件...

  • 实用的shell脚本

    list_sys_status.sh 显示系统使用的以下信息: 主机名、IP地址、子网掩码、网关、DNS服务器IP...

  • 实用的Shell(一)

    查看Home下文件夹大小? 正则表达式[https://zh.wikipedia.org/wiki/%E6%AD%...

  • 实用Shell命令

    文件压缩并分卷 (转)使用tar和split打包分割文件[http://www.cnblogs.com/xiaou...

  • 实用 shell 命令

    全局变量 当前目录和时间 当前文件dirname和basename 文件操作 判断文件(或者目录)是否存在 文件内...

  • 实用shell语句

    批量创建多个目录

  • shell 案例

    Shell编程一 Shell防范ARP攻击 Shell编程二 Shell防范DDos攻击 Shell编程三 ...

网友评论

      本文标题:实用的Shell(二)

      本文链接:https://www.haomeiwen.com/subject/yvklaktx.html