0

I am facing an error when run $ source ~/.bashrc. The error is /usr/share/bash-completion/bash_completion:1512: parse error near `|'.

bash_completion file (the first line is 1512) :

       if ! [[ "$i" =~ ^\~.*|^\/.* ]]; then
            if [[ "$configfile" =~ ^\/etc\/ssh.* ]]; then
                i="/etc/ssh/$i"
            else
                i="$HOME/.ssh/$i"
            fi
        fi

Please help me solve this problem. Thanks!

1
  • 4
    Please confirm that you are trying to source the file into a bash shell (ex. echo $0) Commented Feb 19, 2021 at 2:24

2 Answers 2

0

I ran into the same thing. I did that to myself:

(^\~.*|^\/.*)
0
0

You're probably running a shell other than bash when sourcing that file, which is why you are having an issue. I'm guessing that you are trying to source it from a zsh shell.

$ zsh -c 'if [[ $i =~ ^\~.*|^\/.* ]]; then echo ok; fi'
zsh:1: parse error near `|'

Since programmatic completion is very shell-specific, it's unlikely that you will be able to use a completion script written for bash in the zsh shell, even if you make the syntax zsh-compatible.


Unrelated: The regular expression is testing whether the string in the variable i starts with a slash or a tilde. That test (and the test on $configfile) can portably be done this way:

case $i in
  [~/]*)
    # do nothing
    ;;
  *)
    case $configfile in
      /etc/ssh*)
        i=/etc/ssh/$i
        ;;
      *)
        i=$HOME/.ssh/$i
    esac
esac

Or, the regular expressions could at least be cleaned up as ^[~/] and ^/etc/ssh, respectively. Note that there is absolutely no reason to escape slashes or to match the tail end of the string with .*.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.