"♦: comando no encontrado" en tty después de iniciar sesión


24

Tengo este problema después de actualizar Lubuntu de 12.10 a 13.04.

Presiono Ctrl+ Alt+ 1, introduzca usuario, contraseña, espere dos segundos y obtener: ♦: command not found". Después de este mensaje, puedo escribir comandos sin problemas, pero ¿qué es?

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

Mi .bashrcarchivo es:

# ~/.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

Mi .profilearchivo es:

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

El archivo /etc/profileestá aquí: http://paste.ubuntu.com/5781361/


1
¿Cuál es la salida de echo $PATH? ( Edítelo en su pregunta y luego responda).
Seth

1
¿Puedes subir tus archivos ~ / .bashrc y ~ / .profile a paste.ubuntu.com y publicar los enlaces?
Eric Carvalho

Para referencia futura, la forma se llama "diamante".
user98085

Agregado echo $PATHa mi pregunta.
Vitaly Zdanevich 18/0613

Si usa comillas simples alrededor de su variable de ruta en su '.bashrc', puede causar este problema.
phyatt

Respuestas:


28

Solución alternativa

Primero, creo que te refieres cuando entras en tty1 - Ctrl+ Alt+ F1.

Ahora, creo que está sucediendo lo que ha dicho muy probablemente porque tiene un carácter extraño, como ♦ ( diamantes carácter traje o la tarjeta de identificación especial para un moderador askubuntu ) en ~/.bashrco ~/.profilearchivo u otro archivo que contiene varios comandos de inicialización.

Como puede ver en la siguiente imagen, ~/.bashrcedité el archivo poniendo dentro del carácter ♦ en una sola línea. Como resultado, cuando abro el terminal, aparece el problema descrito por usted:

terminal

Está sucediendo lo mismo cuando entro en tty1 con Ctrl+ Alt+ F1.

Los archivos que contienen comandos de inicialización cuando se invoca un shell: /etc/profile, /etc/bashrc, ~/.bash_login, ~/.profile, ~/.bashrc, ~/.bash_aliasesy tal vez otros. Ver archivos de inicialización de Shell .

Para verificar rápidamente si uno de estos archivos tiene algo mal dentro, puede usar el sourcecomando. Por ejemplo:

source ~/.bashrc

perfil fuente

Solución final

Después de inspeccionar /etc/profiledesde http://paste.ubuntu.com/5781361/ , encontré que en la línea 31 hay "Anulación de derecha a izquierda" -‮ carácter unicode. Simplemente abra el /etc/profilearchivo con sudo -H gedit /etc/profile, asegúrese de eliminar este extraño personaje y el problema desaparecerá.

archivo de perfil

Como diversión, en HTML, por ejemplo, si inserta este carácter unicode usando el código decimal ( ‮) delante de una línea, mire lo que está sucediendo:

¡Este texto está en árabe-inglés!

Otra solución más generalizada.

Encontraremos el comando exacto que causa el error usando un " trampa ".

Primero, tenemos que hacer un nuevo archivo de script en el ~/bindirectorio, llamémoslo lib.trap.sh( gedit ~/bin/lib.trap.sh), con lo siguiente dentro:

lib_name='trap'

lib_version=20130620
#changed from lib_version=20121026 found it at /programming//a/13099228/2353900 to work well at initialization of the shell

stderr_log="/dev/shm/stderr.log"

#
# TO BE SOURCED ONLY ONCE:
#
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##

if test "${g_libs[$lib_name]+_}"; then
    return 0
else
    if test ${#g_libs[@]} == 0; then
        declare -A g_libs
    fi
    g_libs[$lib_name]=$lib_version
fi


#
# MAIN CODE:
#
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##

set -o pipefail  # trace ERR through pipes
set -o errtrace  # trace ERR through 'time command' and other functions
set -o nounset   ## set -u : exit the script if you try to use an uninitialised variable
set -o errexit   ## set -e : exit the script if any statement returns a non-true return value

exec 2>"$stderr_log"


###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##
#
# FUNCTION: EXIT_HANDLER
#
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##

function exit_handler ()
{
    local error_code="$?"

    test $error_code == 0 && return;

    #
    # LOCAL VARIABLES:
    # ------------------------------------------------------------------
    #    
    local i=0
    local regex=''
    local mem=''

    local error_file=''
    local error_lineno=''
    local error_message='unknown'

    local lineno=''


    #
    # PRINT THE HEADER:
    # ------------------------------------------------------------------
    #
    # Color the output if it's an interactive terminal
    test -t 1 && tput bold; tput setf 4                                 ## red bold
    echo -e "\n(!) EXIT HANDLER\n"


    #
    # GETTING LAST ERROR OCCURRED:
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #

    #
    # Read last file from the error log
    # ------------------------------------------------------------------
    #
    if test -f "$stderr_log"
        then
            stderr=$( tail -n 1 "$stderr_log" )
            rm "$stderr_log"
    fi

    #
    # Managing the line to extract information:
    # ------------------------------------------------------------------
    #

    if test -n "$stderr"
        then        
            # Exploding stderr on :
            mem="$IFS"
            local shrunk_stderr=$( echo "$stderr" | sed 's/\: /\:/g' )
            IFS=':'
            local stderr_parts=( $shrunk_stderr )
            IFS="$mem"

            # Storing information on the error
            error_file="${stderr_parts[0]}"
            error_lineno="${stderr_parts[1]}"
            error_message=""

            for (( i = 3; i <= ${#stderr_parts[@]}; i++ ))
                do
                    error_message="$error_message "${stderr_parts[$i-1]}": "
            done

            # Removing last ':' (colon character)
            error_message="${error_message%:*}"

            # Trim
            error_message="$( echo "$error_message" | sed -e 's/^[ \t]*//' | sed -e 's/[ \t]*$//' )"
    fi

    #
    # GETTING BACKTRACE:
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
    _backtrace=$( backtrace 2 )


    #
    # MANAGING THE OUTPUT:
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #

    local lineno=""
    regex='^([a-z]{1,}) ([0-9]{1,})$'

    if [[ $error_lineno =~ $regex ]]

        # The error line was found on the log
        # (e.g. type 'ff' without quotes wherever)
        # --------------------------------------------------------------
        then
            local row="${BASH_REMATCH[1]}"
            lineno="${BASH_REMATCH[2]}"

            echo -e "FILE:\t\t${error_file}"
            echo -e "${row^^}:\t\t${lineno}\n"

            echo -e "ERROR CODE:\t${error_code}"             
            test -t 1 && tput setf 6                                    ## white yellow
            echo -e "ERROR MESSAGE:\n$error_message"


        else
            regex="^${error_file}\$|^${error_file}\s+|\s+${error_file}\s+|\s+${error_file}\$"
            if [[ "$_backtrace" =~ $regex ]]

                # The file was found on the log but not the error line
                # (could not reproduce this case so far)
                # ------------------------------------------------------
                then
                    echo -e "FILE:\t\t$error_file"
                    echo -e "ROW:\t\tunknown\n"

                    echo -e "ERROR CODE:\t${error_code}"
                    test -t 1 && tput setf 6                            ## white yellow
                    echo -e "ERROR MESSAGE:\n${stderr}"

                # Neither the error line nor the error file was found on the log
                # (e.g. type 'cp ffd fdf' without quotes wherever)
                # ------------------------------------------------------
                else
                    #
                    # The error file is the first on backtrace list:

                    # Exploding backtrace on newlines
                    mem=$IFS
                    IFS='
                    '
                    #
                    # Substring: I keep only the carriage return
                    # (others needed only for tabbing purpose)
                    IFS=${IFS:0:1}
                    local lines=( $_backtrace )

                    IFS=$mem

                    error_file=""

                    if test -n "${lines[1]}"
                        then
                            array=( ${lines[1]} )

                            for (( i=2; i<${#array[@]}; i++ ))
                                do
                                    error_file="$error_file ${array[$i]}"
                            done

                            # Trim
                            error_file="$( echo "$error_file" | sed -e 's/^[ \t]*//' | sed -e 's/[ \t]*$//' )"
                    fi

            echo -e "ROW, FILE:\t\t${lines[2]   }\n"

                    echo -e "ERROR CODE:\t${error_code}"
                    test -t 1 && tput setf 6                            ## white yellow
                    if test -n "${stderr}"
                        then
                            echo -e "ERROR MESSAGE:\n${stderr}"
                        else
                            echo -e "ERROR MESSAGE:\n${error_message}"
                    fi
            fi
    fi

    #
    # PRINTING THE BACKTRACE:
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #

    test -t 1 && tput setf 7                                            ## white bold
    echo -e "\n$_backtrace\n"

    #
    # EXITING:
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #

    test -t 1 && tput setf 4                                            ## red bold
    echo "Exiting!"

    test -t 1 && tput sgr0 # Reset terminal

    exit "$error_code"
}
trap exit_handler ERR                                                  # ! ! ! TRAP EXIT ! ! !
#trap exit ERR                                                        # ! ! ! TRAP ERR ! ! ! 


###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##
#
# FUNCTION: BACKTRACE
#
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##

function backtrace
{
    local _start_from_=0

    local params=( "$@" )
    if (( "${#params[@]}" >= "1" ))
        then
            _start_from_="$1"
    fi

    local i=0
    local first=false
    while caller $i > /dev/null
    do
        if test -n "$_start_from_" && (( "$i" + 1   >= "$_start_from_" ))
            then
                if test "$first" == false
                    then
                        echo "BACKTRACE IS:"
                        first=true
                fi
                caller $i
        fi
        let "i=i+1"
    done
}

return 0

Ahora, lo único que debe hacer es colocar la siguiente línea al comienzo del archivo /etc/profile( sudo -H gedit /etc/profile):

source '/home/<user_name>/bin/lib.trap.sh'

Cambio <user_name> con su nombre de usuario. De esta manera, todos los archivos que contienen comandos de inicialización cuando se invoca un shell pasarán por la "trampa".

Para probar si hay un comando incorrecto en /etc/profile por ejemplo, ejecute en los siguientes comandos de la terminal:

fuente bash / etc / profile

Si algo está mal, como en este caso, el resultado será:

trampa

Entonces, ahora sabemos con certeza que hay un problema ( command not found) en/etc/profile archivo en la línea 32 (no está en la línea 31 como se indica arriba porque hemos insertado una nueva línea al comienzo del archivo).

Muchas gracias a Luca Borrione por su guión de esta respuesta que me ayudó a completar esta solución generalizada.


Código agregado de .bashrcy .profilea la pregunta: no puedo encontrar ♦ aquí.
Vitaly Zdanevich

1
@VitalyZdanevich Debe comprobar todos los archivos que contienen comandos de inicialización ( .bash_aliases, .pam_environment, etc) para somenthing extraña en el interior, no necesariamente exactamente este carácter.
Radu Rădeanu

2
Sí, el problema está en la línea 31 de /etc/profile. Tienes algo muy extraño allí. Simplemente elimine todo entre fiy JAVA_HOME, después de presionar uno o dos 'Enter' y todo debería estar bien después. Modifique el archivo consudo gedit /etc/profile
Radu Rădeanu

1
@RyanLoremIpsum No, estoy seguro. El OP había pegado allí, no yo :)
Radu Rădeanu

1
¡Excelente! Aclaro estas dos líneas transparentes en /etc/profile. Extraño bolso.
Vitaly Zdanevich

5

Para depurar los scripts de inicialización de bash, ejecute lo siguiente (después de haber iniciado sesión en la consola virtual).

PS4='+ $BASH_SOURCE:$LINENO:' bash -xlic ''

Lo anterior ejecuta bash en modo interactivo ( -i) login ( -l), igual que el loginprograma cuando inicia sesión en una consola virtual. -c ''hace que salga inmediatamente después de ejecutar los scripts de inicialización, y el -xyPS4=... hace que la salida de cada comando, antes de que los ejecuta, junto con el nombre de archivo y número de línea de ese comando. Eso debería ayudar a determinar qué línea de qué archivo reside ese comando no válido.

En una nota al margen, ♦ es el símbolo que la fuente predeterminada para la consola virtual usa para imprimir caracteres para los que no tiene un símbolo.


1

Mientras busca sus archivos de inicialización, puede ser útil buscar el hexadecimal utilizado para generar el ♦. El código hexadecimal para ♦ es 2666, de acuerdo con el carácter Unicode 'BLACK DIAMOND SUIT' . Nota: Hay al menos otro código hexadecimal, 25C6, que produce el mismo o similar símbolo. Ver los resultados de búsqueda para "diamante". Búsqueda de caracteres Unicode

Quizás algo así \u2666está en uno de los guiones. Del manual de referencia de Bash para echo - "\ uhhhh el carácter Unicode (ISO / IEC 10646) cuyo valor es el valor hexadecimal HHHH (de uno a cuatro dígitos hexadecimales)"

Depende de la codificación de caracteres utilizada, por lo que es posible que desee buscar los más probables primero. echo $LC_CTYPEdebería devolver la codificación de caracteres utilizada por su shell. Vea cómo obtener la codificación de caracteres del terminal


-1 porque en ~/.bash_historyse almacenan los comandos ejecutados interactivamente en PS1.
Radu Rădeanu

Gracias por confirmar. Lo he quitado ¿Debería haber agregado el resto como comentario a tu respuesta, Radu?
iyrin

Oh, no entiendo, ¿qué necesito hacer? ¿Dónde en los archivos de inicialización de Lubuntu? Intenté la búsqueda de texto completo \u2666y ♦ en Catfish (búsqueda de Lubuntu), nada. Yo siembro history, nada. Veo este mensaje solo en tty solo después de iniciar sesión. Después echo $LC_CTYPEme sale la línea vacía.
Vitaly Zdanevich

La ejecución localedebería mostrar LC_CTYPE. locale
iyrin

¡Prueba la respuesta de Radu antes de esta! Si reducimos el conjunto de caracteres utilizado en su tty, puede buscar la aparición del código de carácter correspondiente para el diamante sólido. Esta búsqueda resultaría infructuosa si el hallazgo de RLO de Radu es la causa.
iyrin

0

Escriba la ruta completa a una herramienta conocida que le permitirá editar su archivo bashrc, junto con la ruta completa a su archivo bashrc.

/bin/nano /home/username/.bashrc

Encuentre cualquier abuso a su PATHvariable y coméntelo. Probablemente cuando intentaba agregar algo a su ruta, era una comilla simple en lugar de una comilla doble.

PATH='$PATH:/path/to/new/tool' # very BAD, single quotes won't expand PATH
#    ^                       ^

PATH="$PATH:/path/to/new/tool" # Good! The double quotes allow variable expansion

Copie su .bashrc en una herramienta como https://www.shellcheck.net/ para ver si tiene algún problema evidente con el uso de bash.

Espero que ayude.

Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.