Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I try to build the glibc following the Linux from scratch instruction Chapter 6.9. Glibc-2.14.1, I get a syntax error about $(command).

The simplified problem is that I can type

echo `ls` 

and get the expected result.
However when I type

echo $(ls)

which should do the same thing, but I get

**bash: command substitution: line 78: syntax error near unexpected token `)'
bash: command substitution: line 78: `ls)'**

I don't know why the bash program that I created following the instruction of Linux from scratch cannot handle $() correctly.

The glibc problem is here.

Any idea?

share|improve this question
It is pretty difficult to know what you are doing. Which shell is executing the command? How did you install it? (And please link the instructions you are using) – Matteo Jan 5 '12 at 13:51
You're comparing interactive mode that I can type with a script line 78. What do you get when you type both. What, if you use backticks in the script? I can use both interactively. – user unknown Jan 5 '12 at 14:14
Line 78? I don't see any line 78 here. We can't answer your question if you don't give us all the data. If you're running on a command line, post the full transcript of your session. If you're executing a script, post the whole script. – Gilles Jan 5 '12 at 23:49
@Gilles. I just type the command echo $(ls) on a command line, and the bash tell me syntax error near unexpected token `)'. The bash I use is built following the instruction of LFS.In fact the original problem is here, as Oz Gonaz stated. You may tell me how to solve this original problem instead. Thank you! – Jerome Jan 6 '12 at 0:34

You need to build bash with a better bison (yacc) on your host. Bash uses yacc grammar rules and only GNU bison will generate the correct parsing code for the Bash build.

share|improve this answer
djerome's answer is right. compile bash need yacc which in bison you need exec version-check.sh before all. – user28132 Dec 1 '12 at 10:15

You need to make sure quotes, parentheses and any other grouping structures are nested properly within your script. This error is a typical result of such issues.

share|improve this answer
I just type echo $(ls) on a command line, the bash tells me syntax error. I think this command is nested properly. @l0b0 – Jerome Jan 6 '12 at 13:18
Can you post any relevant env contents, such as $SHELL? – l0b0 Jan 6 '12 at 13:33
TERM=xterm PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin PWD=/ PS1=\u:\w\$ HOME=/root SHLVL=2 _=/tools/bin/env @l0b0 – Jerome Jan 8 '12 at 4:21
SHLVL=2 is interesting - It means you're running a shell within another shell. But is there no $SHELL or similar variable? It should be set by most shells. – l0b0 Jan 8 '12 at 16:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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