shell基本理论知识

(1)查看系统上安装了哪些shell

# cat /etc/shells 
# /etc/shells: valid login shells
/bin/sh
/bin/dash
/bin/bash
/bin/rbash
/bin/ksh93

(2)查看当前使用哪种shell

方法一:
# echo $SHELL
/bin/bash

方法二:
# chsh
Password:
Changing the login shell for berry
Enter the new value, or press ENTER for the default
    Login Shell [/bin/bash]:


(3)改变登录shell

方法一:

chsh [-s shell] [userid]改变登录shell的命令。

chsh -s /bin/ksh93就能把默认的/bin/bash改成/bin/ksh93

等待下一次系统登录才能生效

方法二:

# sudo usermod -s /bin/ksh93 berry
# echo $?
0
# less /etc/passwd | grep berry
berry:x:1000:1000:Berry,,,:/home/berry:/bin/ksh93

(4)显示环境变量

env或者printenv命令。

(5)显示shell变量

set命令可以显示shell变量及其定义的函数

(6)Bourne shell家族使用命令export、unset使shell变量变为“shell+环境”变量,

C-Shell家族使用setenv, unsetenv, set, unset命令设置/删除环境变量,设置/删除shell变量(局部变量)。

(7)shell选项

set -o option (打开/设置一个选项)

set +o option (关闭/复位一个选项)

例子:

set -o monitor shell支持一个叫“作业控制”的功能,打开。

或者

ksh -m (当shell启动时候,以普通的方式制定选项)

(8)显示shell选项

set -o 以一种容易阅读的方式显示所有的shell选项的当前状态。

set +o 以一种紧缩的格式显示相同信息

set -o
allexport          off
braceexpand        on
emacs              on
errexit            off
errtrace           off
functrace          off
hashall            on
histexpand         on
history            on
ignoreeof          off
interactive-comments    on
keyword            off
monitor            on
noclobber          off
noexec             off
noglob             off
nolog              off
notify             off
nounset            off
onecmd             off
physical           off
pipefail           off
posix              off
privileged         off
verbose            off
vi                 off
xtrace             off
[berry@berry:~] set +o
set +o allexport
set -o braceexpand
set -o emacs
set +o errexit
set +o errtrace
set +o functrace
set -o hashall
set -o histexpand
set -o history
set +o ignoreeof
set -o interactive-comments
set +o keyword
set -o monitor
set +o noclobber
set +o noexec
set +o noglob
set +o nolog
set +o notify
set +o nounset
set +o onecmd
set +o physical
set +o pipefail
set +o posix
set +o privileged
set +o verbose
set +o vi
set +o xtrace
原文地址:https://www.cnblogs.com/Berryxiong/p/6289655.html