如何在 Linux 终端中退出 > 模式

如何在 Linux 终端中退出 > 模式

我在远程服务器上使用 Red Hat Enterprise Linux Server 7.9 版。

在使用 source~/.bashrc命令之后,我进入了某种我不太清楚的模式。而不是bash $现在bash #我所拥有的是bash:~ >,通过更改目录,它会继续更改bash:/somedirectory >

有人可以解释一下发生了什么以及如何回到正常模式。

# Generic $dotdir/bashshrc
# Engineering Services (ES)
#
##
# Things the user might wish to set.
export USER_PATH="~/bin"            # Extra paths.
export EDITOR=vi                # Preferred editor.
export PRINTER=lp               # Preferred printer.
export NNTPSERVER=usenet.cisco.com      # Preferred news server.
 

##
# Should the full environment be set up even for non-interactive shells?
# Probably not but here is a variable to control it.
export FULLENV=false                # 'true' or 'false'

##
# Should all paths (even NFS, which might hang) be set up at login?
# The alias "fullpath" is available to setup your full path.  It can
# also be used to change your path by changing USER_PATH above.
export FULLPATH=true                # 'true' or 'false'

###########################################################################
# Everything above this line helps configure the environment.

# This line should not be removed.
dotdir=~/.files; [ -f $dotdir/sys_bashrc ] && . $dotdir/sys_bashrc
[ $FULLENV != "true" ] && [ -z "$PS1" ] && return

###########################################################################
# Everything below this line is run for interactive shells.
# If you wish the full environment even in non-interactive
# shells set FULLENV above to 'true'.

umask 022                        # no write by group or other
export autologout=0              # disable autologout
export FIGNORE=".o"              # don't complete .o files
# export HISTFILE=~/.bash_history  # history file - this setting is now externally enforced by Secops, please don't modify.
# export HISTFILESIZE=500        # history file size - this setting is now externally enforced by Secops, please don't modify.
# export HISTSIZE=128            # save last 128 commands - this setting is now externally enforced by Secops, please don't modify.
export ignoreeof=10              # disable ^D for logout (up to 10)
set -C                           # disable redirect overwrite
set -b                           # enable immediate job notify
export PS1="\h:\w > "            # shell prompt format

##
# Source other rc files after this line.
[ -f ~/.bashrc_LOB ] && . ~/.bashrc_LOB
[ -f ~/.bashrc_BU ] && . ~/.bashrc_BU
[ -f ~/.bashrc_USER ] && . ~/.bashrc_USER

我打开文件来编辑路径。但除了额外的空间来检查写入权限之外,没有进行任何更改。

答案1

虽然>是默认的二次提示(由变量确定$PS2)对于 Bash,您的情况看起来更像是您可能意外更改了主提示符 ( $PS1)。

正如 Paul_Pedant 在评论中提到的,当您尝试执行具有不平衡引号或括号或未终止语句(if ... then ... fi, case ... esac, do ... done)的命令时,会出现辅助提示。

但是,由于您可以更改目录,因此主提示符现在更有可能已更改为~/.bashrc类似于辅助提示符:如果您确实处于辅助提示符处,则您键入的任何命令都将用于扩展任何未完成的引用/括号/语句块首先触发它,只有在完成未完成的块后,该命令才会真正执行。这意味着如果您处于真正的辅助提示符中,您将无法更改目录。

最简单的解决方法是将主提示更改回您更熟悉的值。例如:

export PS1='bash \$ '

\$在主提示中具有特殊意义:如果您是 root,则它会扩展;#如果$您是普通用户,则它会扩展。


更改是由您的以下行引起的~/.bashrc

export PS1="\h:\w > "            # shell prompt format

hostname:current directory您可以将其注释掉,或者如果您发现提示中的显示有用,您可以将该行更改为:

export PS1="\h:\w \$ "            # shell prompt format

让提示中的$/字符按照您以前的方式运行,同时保留提示中显示的主机名和当前工作目录。#

相关内容