syntax error near unexpected token '<' on line 123 in bash_completion.d/git
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.
"< <()" 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
childIs "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
Quoted 6 lines · Andrew Sayers
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.
Quoted 3 lines
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 ')
Quoted 2 lines
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
On 25/07/10 23:19, solsTiCe d'Hiver wrote:
<snip>
Quoted 4 lines
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
Quoted 5 lines · Andrew Sayers
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
Quoted 3 lines
Could you also have a look at
/bin/shand 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
Quoted 4 lines · solsTiCe d'Hiver
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.
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.