Vit*_*ich 24 command-line lubuntu tty login
将 Lubuntu 从 12.10 升级到 13.04 后,我遇到了这个问题。
我按Ctrl+ Alt+ 1,输入登录名,密码,等待两秒钟,然后得到:?: command not found"。在此消息之后,我可以毫无问题地键入命令,但它是什么?
echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/vitaly/bin:/usr/java/jdk1.7.0_17/bin
Run Code Online (Sandbox Code Playgroud)
我的.bashrc文件是:
echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/vitaly/bin:/usr/java/jdk1.7.0_17/bin
Run Code Online (Sandbox Code Playgroud)
我的.profile文件是:
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize
# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar
# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
# Add an "alert" alias for long running commands. Use like so:
# sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
fi
Run Code Online (Sandbox Code Playgroud)
该文件/etc/profile在这里:http : //paste.ubuntu.com/5781361/
Rad*_*anu 28
首先,我认为您指的是何时进入 tty1 - Ctrl+ Alt+ F1。
现在,我认为你所说的最有可能发生,因为你有一个奇怪的角色,比如?(钻石套装字符或askubuntu 版主的特殊徽章)在~/.bashrc或~/.profile文件或其他包含各种初始化命令的文件中。
正如您在下一张图片中看到的,我编辑了~/.bashrc文件,放入 ? 单行字符。结果,当我打开终端时,它得到了你描述的问题:

当我使用Ctrl+ Alt+进入 tty1 时,情况也是如此F1。
调用 shell 时包含初始化命令的文件:/etc/profile、/etc/bashrc、~/.bash_login、 ~/.profile、~/.bashrc,~/.bash_aliases也许还有其他。请参阅Shell 初始化文件。
要快速检查这些文件之一是否有问题,您可以使用source命令。例如:
source ~/.bashrc
Run Code Online (Sandbox Code Playgroud)

/etc/profile从http://paste.ubuntu.com/5781361/检查后,我发现第 31 行有“从右到左覆盖” -‮ unicode 字符。只需打开/etc/profile文件sudo -H gedit /etc/profile,确保删除这个奇怪的字符,问题就会消失。

作为娱乐,例如在 HTML 中,如果您‮在一行前使用十进制代码 ( )插入这个 unicode 字符,看看发生了什么:
?这篇文章是阿拉伯语-英语!
我们将使用“陷阱”找到导致错误的确切命令。
首先,我们必须在~/bin目录中创建一个新的脚本文件,我们称之为lib.trap.sh( gedit ~/bin/lib.trap.sh),里面有以下内容:
source ~/.bashrc
Run Code Online (Sandbox Code Playgroud)
现在,您唯一要做的就是将下一行放在文件/etc/profile( sudo -H gedit /etc/profile)的开头:
source '/home/<user_name>/bin/lib.trap.sh'
Run Code Online (Sandbox Code Playgroud)
更改<user_name>为您的用户名。像这样,所有在调用 shell 时包含初始化命令的文件都将通过“陷阱”。
/etc/profile例如,要测试是否有错误的命令,请在终端下运行命令:
bash 源 /etc/profile
如果出现问题,例如在这种情况下,结果将是:

所以,现在我们确定文件中第 32 行有问题(command not found)/etc/profile(它不是上面的第 31 行,因为我们在文件的开头插入了一个新行)。
非常感谢Luca Borrione从这个答案中提供的脚本帮助我完成了这个通用解决方案。
要调试 bash 的初始化脚本,请运行以下命令(在虚拟控制台登录后)。
PS4='+ $BASH_SOURCE:$LINENO:' bash -xlic ''
Run Code Online (Sandbox Code Playgroud)
以上以交互 ( -i) 登录 ( -l) 模式运行 bash,与登录login虚拟控制台时的程序相同。-c ''使得它立即退出通过初始化脚本运行后,将-x和PS4=...使它输出的每个命令,它运行之前,与该命令的文件名和行号。这应该有助于确定无效命令驻留在哪个文件的哪一行。
附带说明, ? 是虚拟控制台的默认字体用于打印它没有符号的字符的符号。