问题

当用户使用具有 korn shell (ksh) 的用户登录终端时,会出现以下消息:

Shopt: Not Found [No Such File Or Directory]

解决方案2

将用户 test1 的 Shell 从 ksh 更改为 bash。

  1. 验证我们当前的 Shell:
# chsh -l test1
/bin/sh
/bin/bash
/sbin/nologin
/bin/dash
/bin/tcsh
/bin/csh
/bin/ksh
  1. 改成bash
# chsh -s /bin/bash test1
Changing shell for test1.
Shell changed.
# cat /etc/passwd|grep -i test1
test1:x:54323:112::/home/test1:/bin/bash
#
  1. 验证和测试新的shell:
# su - test1
$ whoami
test1
$
欢迎来到之路教程(on itroad-com)

解决方案1

  1. 编辑文件 /etc/profile 和注释第 51 行:shopt -s histappend:
# vi /etc/profile
#shopt -s histappend
  1. 重新加载配置文件或者退出终端并重新登录。
# source /etc/profile .
  1. 重新登录:
# su - test1
$
$ whoami
test1

例如 :

# cat /root/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
  . ~/.bashrc
fi

用户特定环境和启动程序:

PATH=$PATH:$HOME/bin
shopt -s histappend
export PATH
export HISTTIMEFORMAT="%

从 /etc/profile 中删除它:

# cat /etc/profile| grep -i shopt
#
Shopt: Not Found [No Such File Or Directory]

解决方案

在 /etc/profile 上添加了以下行:

shopt -s histappend

笔记 :
/etc/profile 是一个配置文件,它为所有用户设置全局环境。
根据 shopt 的手册页:

# man shopt
 shopt is part of BASH_BUILTINS
        -s  Display readline key sequences bound to macros and the strings they output in such 
            a way that they can be re-read.
        histappend
            If set, the history list is appended to the file named by the value of the 
            HISTFILE variable when the shell exits, rather than overwriting the file

问题在于 KSH,因为 shopt 是 BASH_BUILTINS 的一部分。
根据 /etc/passwd 文件,用户 shell 是“ksh”而不是“bash”:

# grep -i test /etc/passwd
testuserX:x:54322:54323::/home/testuserX:/bin/bash
test1:x:54323:112::/home/test1:/bin/ksh

==============
/etc/profile :

47 TMOUT=14400
48 HOSTNAME=`/bin/hostname 2>/dev/null`
49 HISTSIZE=1000
50 HISTTIMEFORMAT='%F.%T '
51 shopt -s histappend   <===============================  Line was added

如果我们切换到用户测试,我们会发现以下消息:

# su - test1
/etc/profile[277]: shopt: not found [No such file or directory]
日期:2020-09-17 00:14:10 来源:oir作者:oir