6

When I open terminal I get these errors:

bash: /usr/share/bash-completion/bash_completion: line 171: syntax error near unexpected token `}'
bash: /usr/share/bash-completion/bash_completion: line 171: `}'

And it's because of this area of the bash-completion file:

_upvar()
{
    if unset -v "$1"; then           # Unset & validate varname
        if (( $# == 2 )); then
            eval $1=\"\$2\"          # Return single value
        else
            eval $1=\(\"\${@:2}\"\)  # Return array
        fi
    fi
}

Why do I get an error in that part?

  • 1
    I tried source /usr/share/bash-completion/bash_completion and got no syntax error. Please post the output of lsb_release -d and echo $BASH_VERSION. – wjandrea Jun 15 '18 at 18:05
  • 1
    Can you please add your bash version (echo $BASH_VERSION) and also the output of cat -net src so we can see if there are any funny characters that may be affecting things – steeldriver Jun 15 '18 at 18:09
  • 1
    ... for example, I can reproduce the error if I add a carriage return after the final fi – steeldriver Jun 15 '18 at 18:36
  • 2
    @SergiyKolodyazhnyy I have retracted my close vote. I have looked further into this. This actually appears to be a segment of the /var/share/bash-completion/bash-completion file from Ubuntu 18.04. Without seeing the entire file there is no way to know if there is a typo or something in that area of line 171 that doesn't have a matching {. I am going to agree with WinEunuuchs2Unix above about this being a bug then. – Terrance Jun 16 '18 at 3:44
  • 2
    Could you please edit your question to include the output of md5sum /usr/share/bash-completion/bash_completion and LC_MESSAGES=POSIX apt-cache policy "$(dpkg-query -S /usr/share/bash-completion/bash_completion | cut -d : -f 1)"? Thanks. – David Foerster Jun 17 '18 at 13:52
3

I think this might be the same issue as this U&L post: you have an alias for fi. The script is fine under most circumstances, but aliasing shell keywords can cause unexpected problems:

$ alias fi=find
$ . /usr/share/bash-completion/bash_completion
bash: /usr/share/bash-completion/bash_completion: line 171: syntax error near unexpected token `}'
bash: /usr/share/bash-completion/bash_completion: line 171: `}'

That function, despite being around line 170, is the first place in that file which uses fi. Depending on where exactly you placed this alias definition, and where exactly the bash-completion scripts are being sourced by bash, this might be the first time after that alias is set that fi is used.

| improve this answer | |
4

To see if any of your aliases are conflicting with a bash built-in or a system command use this script:

#!/bin/bash -i

# NAME: alias-check
# PATH: /mnt/e/bin
# DESC: Verify alias doesn't conflict with bash built-in
# DATE: June 17, 2018.

# Get aliases
alias > /tmp/alias.lst
sed -i 's/=.*//; s/alias //g' /tmp/alias.lst
#cat /tmp/alias.lst
while read -r line 
do 
   command type -a ${line}
done< /tmp/alias.lst

Testing bad aliases

Edit ~/.bashrc and insert these "bad" aliases:

alias fi=find
alias test='ls test'

Now run the script alias-check:

bash: /home/rick/.bashrc: line 171: syntax error: unexpected end of file
alert is aliased to `notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e 's/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//')"'
cdd is aliased to `cd /home/rick/SERVER/#/Dump'
cdh is aliased to `cd /home/rick'
cdm is aliased to `cd /media/rick/ST9_Win7/Users/Person/Music/iTunes/iTunes Media/Music'
egrep is aliased to `egrep --color=auto'
egrep is /bin/egrep
fgrep is aliased to `fgrep --color=auto'
fgrep is /bin/fgrep
fi is aliased to `find'
fi is a shell keyword
grep is aliased to `grep --color=auto'
grep is /bin/grep
l is aliased to `ls -CF'
la is aliased to `ls -A'
ll is aliased to `ls -alF'
ls is aliased to `ls --color=auto'
ls is /bin/ls
lsdrv is aliased to `lsblk -o NAME,FSTYPE,LABEL,MOUNTPOINT,SIZE,MODEL'
redalert is aliased to `notify-send --urgency=critical -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e 's/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//')"'
sudo is aliased to `sudo '
sudo is /usr/bin/sudo
test is aliased to `ls test'
test is a shell builtin
test is /usr/bin/test
zenity is aliased to `zenity 2>/dev/null'
zenity is /mnt/e/usr/local/bin/zenity
zenity is /usr/local/bin/zenity
zenity is /usr/bin/zenity

Notice the lines:

  • fi is a shell keyword
  • test is a shell builtin

Look for these types of errors in your aliases.

After testing don't forget to remove the aliases fi and test and save ~/.bashrc again.

You can't run the test by simply issuing alias at the command line because the first line of the script #!/bin/bash -i loads a new shell using ~/.bashrc.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.