# [bash-completion] syntax error near unexpected token '<' on line 123 in bash_completion.d/git

7 messages from 2010-07-25 to 2010-07-27. Participants: solsTiCe d'Hiver, Ævar Arnfjörð Bjarmason, Andrew Sayers.
Thread: https://gitlist.dev/t/24509

## solsTiCe d'Hiver, 2010-07-25 11:12

Subject: [bash-completion] syntax error near unexpected token '<' on line 123 in bash_completion.d/git
Message-ID: <1280056320.7883.9.camel@soho.example.org>
URL: https://gitlist.dev/e/1280056320.7883.9.camel%40soho.example.org

```
hello,
I want to report a tiny "bug" (?) and I couldn't find a bug tracker so
here I am

When I boot my pc, I got an error on my console before gdm kick in to
launch gnome.

This is an error in /etc/bash_completion.d/git; it says
syntax error near unexpected token '<' on line 123

I use git 1.7.2 and bash 4.1.007 and the line 123
of /etc/bash_completion.d/git looks like this

	done < <(git config -z --get-regexp '^(svn-remote\..*\.url|bash
\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')

I think that may be there is too much < there.

but strangely if I source manually that file in a bash it works without
error.

originally reported there: http://bugs.archlinux.org/task/20264

P.S.: I have not subscribed to the ML.

```

## Ævar Arnfjörð Bjarmason, 2010-07-25 11:49

Subject: Re: [bash-completion] syntax error near unexpected token '<' on line 123 in bash_completion.d/git
Message-ID: <AANLkTimYo9itgVrL100mD8sU52h7f2F84PuJtCO3yKsJ@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTimYo9itgVrL100mD8sU52h7f2F84PuJtCO3yKsJ%40mail.gmail.com
In-Reply-To: <1280056320.7883.9.camel@soho.example.org>

```
On Sun, Jul 25, 2010 at 11:12, solsTiCe d'Hiver
<solstice.dhiver@gmail.com> wrote:

>        done < <(git config -z --get-regexp '^(svn-remote\..*\.url|bash
> \.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')
>
> I think that may be there is too much < there.

That's not a syntax error.

CC-ing Andrew Sayers who added this feature.

```

## Andrew Sayers, 2010-07-25 20:01

Subject: Re: [bash-completion] syntax error near unexpected token '<' on line 123 in bash_completion.d/git
Message-ID: <4C4C982C.20904@pileofstuff.org>
URL: https://gitlist.dev/e/4C4C982C.20904%40pileofstuff.org
In-Reply-To: <1280056320.7883.9.camel@soho.example.org>

```
"< <()" is indeed correct here: the first "<" is a normal shell
redirect, and the "<()" creates a sub-shell to read input from.  This
was the least messy way I could find to read variables into a shell.  "<
$()" won't do the job, and a normal pipe won't either:

$ FOO=parent ; echo child | { read ; FOO="$REPLY" ; } ; echo $FOO
parent
$ FOO=parent ; { read ; FOO="$REPLY" ; } < $( echo child ) ; echo $FOO
bash: child: No such file or directory
parent
$ FOO=parent ; { read ; FOO="$REPLY" ; } < <( echo child ) ; echo $FOO
child


Is "syntax error near unexpected token '<' on line 123" the complete
text of the error message you get?  bash 4.1.5 always prepends "bash: "
to such errors for me:

$ while false ; do echo foo ; done < ;
bash: syntax error near unexpected token `;'

If this is the complete error text, then I suspect you may have somehow
got bash completion in a non-bash shell.  Could you add this on line 98
and let me know what it says:

echo $BASH_VERSION $BASHOPTS

If it really is bash, $BASHOPTS might help me to replicate this problem
(or I might have to read the man page some more).

	- Andrew

```

## solsTiCe d'Hiver, 2010-07-25 22:19

Subject: Re: [bash-completion] syntax error near unexpected token '<' on line 123 in bash_completion.d/git
Message-ID: <1280096368.7211.2.camel@soho.example.org>
URL: https://gitlist.dev/e/1280096368.7211.2.camel%40soho.example.org
In-Reply-To: <4C4C982C.20904@pileofstuff.org>

```
Le dimanche 25 juillet 2010 à 21:01 +0100, Andrew Sayers a écrit : 
> bash 4.1.5 always prepends "bash: "
> to such errors for me:
> 
> $ while false ; do echo foo ; done < ;
> bash: syntax error near unexpected token `;'
> 
bash 4.1.7 does that too here.

> If this is the complete error text, then I suspect you may have somehow
> got bash completion in a non-bash shell.
> 
the complete message is:
/etc/bash_completion.d/git: line 123: syntax error near unexpected token
'<'
/etc/bash_completion.d/git: line 123: done < <(git config -z
--get-regexp '^(svn-remote\..*\.url|bash > \.showupstream)$' 2>/dev/null
| tr '\0\n' '\n ')

> Could you add this on line 98 and let me know what it says:
> echo $BASH_VERSION $BASHOPTS

When I add the above command at line 98, it shows it is really bash
running:
4.1.7(2)-release
cmdhist:expand_aliases:extglob:extquote:force_fignore:interactive_comments:progcomp:promptvars:sourcepath 

```

## Andrew Sayers, 2010-07-26 21:39

Subject: Re: [bash-completion] syntax error near unexpected token '<' on line 123 in bash_completion.d/git
Message-ID: <4C4E00AE.7010904@pileofstuff.org>
URL: https://gitlist.dev/e/4C4E00AE.7010904%40pileofstuff.org
In-Reply-To: <1280096368.7211.2.camel@soho.example.org>

```
On 25/07/10 23:19, solsTiCe d'Hiver wrote:
<snip>
> When I add the above command at line 98, it shows it is really bash
> running:
> 4.1.7(2)-release
> cmdhist:expand_aliases:extglob:extquote:force_fignore:interactive_comments:progcomp:promptvars:sourcepath 

Hmm, that's interesting.  It's certainly bash, but I don't see
"login_shell" in the list, which suggests that something is loading bash
completion stuff in a non-interactive shell that has no need for it.
That might increase your your boot time a bit, so you may want to take
it up with Arch Linux when we've got to the bottom of this.

One way I've found to replicate your behaviour is to call bash as sh:

$ ln -s /bin/bash sh
$ ./sh -c 'echo $BASH_VERSION'
4.1.5(1)-release
$ ./sh contrib/completion/git-completion.bash
contrib/completion/git-completion.bash: line 123: ...

Again, this fits with the theory that some non-interactive shell is
wrongly loading this stuff.

This time, could you tell me what the following debug messages print:

echo $BASHOPTS -- $SHELLOPTS -- $POSIXLY_CORRECT
tr '\0' ' ' < /proc/$$/cmdline ; echo

Could you also have a look at /bin/sh and any other files that might be
(incorrectly?) symlinked to bash?

On a wider point, I consider the bash/sh behaviour above to be a bug,
whether or not it's the cause of this specific problem.  Unless someone
wants to tell me about git's long-standing policy against it, I'll try
and find some time to send in a patch warning usefully in this case.

	- Andrew

```

## solsTiCe d'Hiver, 2010-07-27 09:24

Subject: Re: [bash-completion] syntax error near unexpected token '<' on line 123 in bash_completion.d/git
Message-ID: <1280222655.9955.32.camel@soho.example.org>
URL: https://gitlist.dev/e/1280222655.9955.32.camel%40soho.example.org
In-Reply-To: <4C4E00AE.7010904@pileofstuff.org>

```
Le lundi 26 juillet 2010 à 22:39 +0100, Andrew Sayers a écrit : 
> This time, could you tell me what the following debug messages print:
> 
> echo $BASHOPTS -- $SHELLOPTS -- $POSIXLY_CORRECT
> tr '\0' ' ' < /proc/$$/cmdline ; echo
> 
cmdhist:expand_aliases:extglob:extquote:force_fignore:interactive_comments:progcomp:promptvars:sourcepath -- braceexpand:hashshell:interactive-comments:posix -- y
/bin/sh /usr/sbin/gdm

> Could you also have a look at /bin/sh and any other files that might be
> (incorrectly?) symlinked to bash?
> 
I have included gdm in the DAEMON list in my /etc/rc.conf. I tried to
run it from inittab in a more usual way and get the same ?!

When I looked at /usr/sbin/gdm, I found the cause of this problem, look
at that

#!/bin/sh
#
# A script so that
#    1) we read the standard system env vars
#    2) syadmins/integrators can add their own private options etc...

test -f /etc/profile && . /etc/profile

# Make sure LANG is set
#
if [ -z "$LANG" ]
then
  if [ -f /etc/sysconfig/language ]
  then
    LANG=`. /etc/sysconfig/language; echo $RC_LANG`
    export LANG
  fi
fi

exec /usr/sbin/gdm-binary "$@"

Note: it's not a custom archlinux script. This is straight from gdm
release 2.30.4

so it's a non-login shell (sh) script that source /etc/profile and
breaks standard behavior. no wonder that bash_completion stuff is run
there

```

## solsTiCe d'Hiver, 2010-07-27 10:43

Subject: Re: [bash-completion] syntax error near unexpected token '<' on line 123 in bash_completion.d/git
Message-ID: <1280227428.7654.5.camel@soho.example.org>
URL: https://gitlist.dev/e/1280227428.7654.5.camel%40soho.example.org
In-Reply-To: <4C4E00AE.7010904@pileofstuff.org>

```
it appears there is a bug in /etc/profile in archlinux that mis-detects
sh as bash and run bash specific script like bash_completion.

```
