Debugging .bash_aliases File in Ubuntu 12.04

Asked by Julianloui

2013-11-26

After I revised my .bash_aliases file a couple of times today, Ubuntu 12.04 sudddenly stopped recognizing it. What can I do to fix this problem? Thanks.

(1) Output of bash .bash_aliases command :

.bash_aliases: line 80: unexpected EOF while looking for matching `''
.bash_aliases: line 82: syntax error: unexpected end of file

(2) Line 80 and also file's last line.

alias edog='firefox www.eguidedog.net'

Julianloui
(2) Line 80 and also file's last line.
------------------------------------------------------------- U R G E N T ---------------------------------------------------
PS It would be extremely hepful for this site to provide a spellchecker as an interim soultion to the annoying egregious bug that has been afflicting all users through the years, namely that of users' inability in correcting spelling errors or in revising a post after publishing it. All other Linux or Unix-related sites do not suffer from this unnecessary self-imposed AFFLICTION!!
---------------------------------------------------------------------------------------------------------------------------------------

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

What is the output of:

cat -n ~/.bashrc; echo; lsb_release -a; uname -a

Thanks

Revision history for this message
Julianloui (julianloui) said :
#2

Andrew,

I obtianed the following responses from Ubuntu 12.04. per your request.
Julianloui

     1 # ~/.bashrc: executed by bash(1) for non-login shells.
     2 # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
     3 # for examples
     4
     5 # If not running interactively, don't do anything
     6 [ -z "$PS1" ] && return
     7
     8 # don't put duplicate lines or lines starting with space in the history.
     9 # See bash(1) for more options
    10 HISTCONTROL=ignoreboth
    11
    12 # append to the history file, don't overwrite it
    13 shopt -s histappend
    14
    15 # for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
    16 HISTSIZE=1000
    17 HISTFILESIZE=2000
    18
    19 # check the window size after each command and, if necessary,
    20 # update the values of LINES and COLUMNS.
    21 shopt -s checkwinsize
    22
    23 # If set, the pattern "**" used in a pathname expansion context will
    24 # match all files and zero or more directories and subdirectories.
    25 #shopt -s globstar
    26
    27 # make less more friendly for non-text input files, see lesspipe(1)
    28 [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
    29
    30 # set variable identifying the chroot you work in (used in the prompt below)
    31 if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    32 debian_chroot=$(cat /etc/debian_chroot)
    33 fi
    34

    35 # set a fancy prompt (non-color, unless we know we "want" color)
    36 case "$TERM" in
    37 xterm-color) color_prompt=yes;;
    38 esac
    39
    40 # uncomment for a colored prompt, if the terminal has the capability; turned
    41 # off by default to not distract the user: the focus in a terminal window
    42 # should be on the output of commands, not on the prompt
    43 #force_color_prompt=yes
    44
    45 if [ -n "$force_color_prompt" ]; then
    46 if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
    47 # We have color support; assume it's compliant with Ecma-48
    48 # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
    49 # a case would tend to support setf rather than setaf.)
    50 color_prompt=yes
    51 else
    52 color_prompt=
    53 fi
    54 fi
    55
    56 if [ "$color_prompt" = yes ]; then
    57 PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    58 else

    59 PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    60 fi
    61 unset color_prompt force_color_prompt
    62
    63 # If this is an xterm set the title to user@host:dir
    64 case "$TERM" in
    65 xterm*|rxvt*)
    66 PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    67 ;;
    68 *)
    69 ;;
    70 esac
    71
    72 # enable color support of ls and also add handy aliases
    73 if [ -x /usr/bin/dircolors ]; then
    74 test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    75 alias ls='ls --color=auto'
    76 #alias dir='dir --color=auto'
    77 #alias vdir='vdir --color=auto'
    78

    79 alias grep='grep --color=auto'
    80 alias fgrep='fgrep --color=auto'
    81 alias egrep='egrep --color=auto'
    82 fi
    83
    84 # some more ls aliases
    85 alias ll='ls -alF'
    86 alias la='ls -A'
    87 alias l='ls -CF'
    88
    89 # Add an "alert" alias for long running commands. Use like so:
    90 # sleep 10; alert
    91 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$//'\'')"'
    92
    93 # Alias definitions.
    94 # You may want to put all your additions into a separate file like
    95 # ~/.bash_aliases, instead of adding them here directly.
    96 # See /usr/share/doc/bash-doc/examples in the bash-doc package.
    97
    98 if [ -f ~/.bash_aliases ]; then
    99 . ~/.bash_aliases
   100 fi
   101
   102 # enable programmable completion features (you don't need to enable
   103 # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
   104 # sources /etc/bash.bashrc).
   105 if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
   106 . /etc/bash_completion
   107 fi
   108
   109 if [ -f $HOME/.bash_aliases ]
   110 then
   111 . $HOME/.bash_aliases
   112 fi

Distributor ID: Ubuntu
Description: Ubuntu 12.04.3 LTS
Release: 12.04
Codename: precise
Linux ch 3.2.0-55-generic-pae #85-Ubuntu SMP Wed Oct 2 14:03:15 UTC 2013 i686 i686 i386 GNU/Linux

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#3

Ok so using that output and your first output in the initial question:

.bash_aliases: line 80: unexpected EOF while looking for matching `''
.bash_aliases: line 82: syntax error: unexpected end of file

Can you see the issue?

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#4

Ok so using that output and your first output in the initial question:

.bash_aliases: line 80: unexpected EOF while looking for matching `''
.bash_aliases: line 82: syntax error: unexpected end of file

Can you see the issue?

Revision history for this message
Julianloui (julianloui) said :
#5

I don't.

Th original LInux error messaage had to do with the .bash_aliases file's lines 80 and 82. As I pointed out, there appear to be only 80 lines in it as far as my naked eyes can see.

Can you tell me how to check this file's EOF characater? Thanks.

Julianlouil

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#6

sorry:

cat -n ~/.bash_aliases

What is the output (Wrong file earlier)

Thanks

Revision history for this message
Julianloui (julianloui) said :
#7

Andrew,

Being eager to use my regular alises, today I decided to replace the problematic new version of .bash_aliases with an older one. Of course, as a result, I no longer have access to it. The older version works but does not include the new entries.

cat -n ~/.bash_aliases shows the replacement version with line nubers and nothing unusual. Thanks for showing me this way of listing a text file with line numbers. Out of curiosity, I used the vi editor to look at the end of this file's binary codes and failed to see any EOF code.

Someone said it could be 62 or 26. Is this information correct?

Julianloui

Revision history for this message
Best Manfred Hampl (m-hampl) said :
#8

What the error message talks about is not a EOF character, but the "end of file" condition as such (which is indicated by the fact that as many characters have been read as indicated in the index information for the file).

I assume the your error in the .bash_aliases file was an odd number of ' characters.

As shown in your example
alias edog='firefox www.eguidedog.net'
you see that the ' characters mark the beginning and end of the alias value. They must appear in pairs.
If you erroneously delete the ending ' character, there is a string that starts with a ' and there is the end of file condition coming before the closing ' has appeared. This will lead to the error messages shown.

Note, that also a missing ' in one of the earlier lines will finally lead to such error messages, because the interpreter will try to pair all ' characters and recognize a missing ' only at the end of the file.

One common cause for such errors is a mixing of the different quote characters ' ´ ` "
For .bash_aliases I would expect only straight single quotes '

Revision history for this message
Julianloui (julianloui) said :
#9

Manfred,

Thank you very much for an excellently clear explanation. I'll try to debug with your rule when I encounter a simailar problem
again in the future.

Julianloui

Revision history for this message
Julianloui (julianloui) said :
#10

Thanks Manfred Hampl, that solved my question.