Syntax error: word unexpected (expecting ")") - arm

Problem in short - In Linux, whenever we get the following error
"Syntax error: word unexpected (expecting ")")", what does it generally mean?
Problem in details - I have been trying to cross-compile Qt 4.6 as per the Sourcery tool chain on Ubuntu 10.04 (Lucid Lynx). I followed the exact steps mentioned at the link compiling Qt-4.6. But I get the following error right in the ./configure step -
/home/weds/qt-everywhere-opensource-src-4.6.1/bin/qmake: 1: Syntax error: word unexpected (expecting ")")
Searching on the Internet I found lots of posts regarding this error and read all of them. What is this error and how can I solve it?
P.S 1 - the Sourcery toolchain is present inside /opt/ folder and my PATH variable is correctly pointing to it.
P.S 2 - This toolchain was not installed manually by me. Rather it was provided by a vendor as a .tgz file which I extracted inside the /opt/ folder.

That's an error reported by the Almquist shell or any of its derivatives like Dash (and Dash happened to be the default implementation of /bin/sh on Ubuntu 10.04 (Lucid Lynx)) when a word is found while parsing the syntax of a script where a ) is expected instead, for instance like in this case statement:
dash -c 'case a in b c) :; esac'
dash: 1: Syntax error: word unexpected (expecting ")")
That's because after b , the only thing that is expected after is ), (though actually | would also be allowed) so that c word is unexpected.
dash -c 'myfunc( something'
dash: 1: Syntax error: word unexpected (expecting ")")
One case where that can happen is if the script has been written on or transferred through a Microsoft OS where text line endings are CRLF instead of just LF.
A
case a in b) cmd1;;
c) cmd2
esac
script written on MS-DOS would appear as:
case a in b) cmd1;;<CR>
c) cmd2<CR>
esac<CR>
on Unix and that c would be an extra word after the <CR> word.
Here that's unlikely as your error reports the problem being on the first line of the script and most scripts start with the #! /path/to/interpreter shebang line.
Another possibility is that that script you're trying to run has been written on the assumption that sh was bash and uses constructs that are not portable to other sh implementations.
Since you're using an outdated and no longer maintained OS, it's also possible that you're running into a bug in that version of Dash. You could run dpkg-reconfigure dash and tell the system not to use Dash for sh (but Bash instead) to see if that helps.
Again, it is unlikely to be on the first line.
What sounds more likely is that that qmake file is not a script, but a binary executable that is not recognised as such by the system, for instance because it is of a binary format for the wrong architecture or it has been corrupted in transfer.
In that case, when the system fails to recognise it as a native executable, the invoking application would try to run sh on it as if it was a shell script, and the presence of a ( character in the file could cause Dash to fail with such an error.
On my system:
dash /bin/touch
/bin/touch: 1: /bin/touch: Syntax error: word unexpected (expecting ")")
And if you look at the content of /bin/touch as if it were a script, you see:
^?ELF^B^A^A^#^#^#^#^#^#^#^#^#^B^#>^#^A^#^#^#5&#^#^#^#^#^##^#^#^#^#^#^#^#(ô^#^#...

An answer to this seems to be posted in the instructions to which you linked.
Admittedly it's a long way down in the comments but it didn't take long to search for qmake: Syntax error: word unexpected.
Quote:
Tej says: January 4, 2013 at 12:20 pm
Ok, I have solved the Problem. Its very unfortunate that ppl did not
tell what actually is the problem. Problem is we have to use Host
qmake. For that whatever Export (export
PATH=/usr/local/arm/4.3.2/bin:$PATH etc.) we did in step during tslib
installation, we have to undo all of that. Thats it.
Hope that help someone
In case that's not clear, Tej suggests that it would seem that you're trying to run the cross-compiled qmake on the host system.

In 99% of the cases it is a wrong file transfer mode, ASCII or binary.
Try to extract the toolchain directly on the target system.

I was writing a C++ program on Ubuntu 18.04 (Bionic Beaver) when this problem came around. The cause was that the file name of the program contained the characters "(" and ")". After renaming the files, it worked for me.

This error can also be thrown when calling a NodeJS script from a shell script, without providing the correct shebang line in NodeJS:
#!/usr/bin/env node
// Rest of your NodeJS script

A weird fix for me was deleting file package-lock.json and the node_modules folder, and then building the Docker image again.

Sometimes this error occurs just because the directory in which you are currently working has "wrong naming convention" .. like it could be
demo_project (copy)
my_project_1 (another copy)
The correct naming convention says
1. demo_project_copy
2. my_project_1_another_copy

Related

Trying to compile xf86drm.h example

On this page https://raw.githubusercontent.com/dvdhrm/docs/master/drm-howto/modeset.c someone has published an example on how to properly use the drm api.
I downloaded the source file compiled it with gcc -I/usr/include/drm/ modeset.h -o modeset, marked it as executeable chmod +x modeset and launched it ./modeset
Output:
michael#lord:~/Documents/cpp/modeset$ ./modeset
./modeset: line 1: $'gpchC014\310\b\032\231\253\267+\277\331\022\225I\021': command not found
./modeset: line 17: syntax error near unexpected token `$'\375?\250\001\177\001\001''
./modeset: line 17: `ø?¨
ø?¨
ø?¨ø?¨0ø?¨2ø?¨4ø?¨6ø?¨8ø?¨9ø?¨:ø?¨;ø?¨<ø?¨=ø?¨>ø?¨Pø?¨Rø?¨Tø?¨Vø?¨Xø?¨Zø?¨\ø?¨^ø?¨`ø?¨bø?¨dø?¨fø?¨hø?¨jø?¨lø?¨nø?¨ø?¨ø?¨ø?¨ø?¨ø?¨ø?¨ø?¨ø?¨ ø?¨¢ø?¨¤ø?¨¦ø?¨¨ø?¨ªø?¨¬ø?¨®ø?¨°ø?¨±ø?¨²ø?¨³ø?¨´ø?¨µø?¨¶ø?¨·ø?¨¸ø?¨¹ø?¨ºø?¨»ø?¨¼ø?¨½ø?¨¾ø?¨¿ø?¨ðø?¨òø?¨ôø?¨öø?¨øø?¨úø?¨üø?¨þø?¨ù?¨ù?¨ù?¨ù?¨ù?¨ù?¨ù?¨ù?¨ù?¨ù?¨Aù?¨Cù?¨Eù?¨Gù?¨Iù?¨Kù?¨Mù?¨Où?¨aù?¨cù?¨eù?¨gù?¨iù?¨kù?¨mù?¨où?¨qù?¨sù?¨uù?¨wù?¨yù?¨{ù?¨}ù?¨ù?¨ù?¨ù?¨ù?¨ù?¨ù?¨ù?¨ù?¨ù?¨Áù?¨Ãù?¨Åù?¨Çù?¨Éù?¨Ëù?¨Íù?¨Ïù?¨Ñù?¨Óù?¨Õù?¨×ù?¨Ùù?¨Ûù?¨Ýù?¨ßù?¨ñù?¨óù?¨õù?¨÷ù?¨ùù?¨ûù?¨ýù?¨ÿù?¨ú?¨ú?¨ú?¨ú?¨ ú?¨
ú?¨ú?¨1ú?¨3ú?¨5ú?¨7ú?¨9ú?¨;ú?¨=ú?¨?ú?¨Qú?¨Sú?¨Uú?¨Wú?¨Yú?¨[ú?¨]ú?¨_ú?¨qú?¨sú?¨uú?¨wú?¨yú?¨{ú?¨}ú?¨ú?¨ú?¨ú?¨ú?¨ú?¨ú?¨ú?¨ú?¨ú?¨¡ú?¨¢ú?¨£ú?¨¤ú?¨¦ú?¨¨ú?¨ªú?¨¬ú?¨®ú?¨Àú?¨Âú?¨Äú?¨Æú?¨Èú?¨Êú?¨Ìú?¨Îú?¨ðú?¨òú?¨ôú?¨öú?¨øú?¨úú?¨üú?¨þú?¨û?¨û?¨û?¨û?¨û?¨û?¨û?¨û?¨ û?¨"û?¨$û?¨&û?¨(û?¨*û?¨,û?¨.û?¨Pû?¨Rû?¨Tû?¨Vû?¨Xû?¨Zû?¨\û?¨^û?¨`û?¨bû?¨dû?¨fû?¨hû?¨jû?¨lû?¨nû?¨û?¨û?¨û?¨û?¨û?¨û?¨û?¨û?¨Ðû?¨Òû?¨Ôû?¨Öû?¨Øû?¨Úû?¨Üû?¨Þû?¨àû?¨âû?¨äû?¨æû?¨èû?¨êû?¨ìû?¨îû?¨ðû?¨òû?¨ôû?¨öû?¨øû?¨úû?¨üû?¨þû?¨ü?¨ü?¨ü?¨ü?¨ü?¨ü?¨ü?¨ü?¨Pü?¨Rü?¨Tü?¨Vü?¨Xü?¨Zü?¨\ü?¨^ü?¨pü?¨rü?¨tü?¨vü?¨xü?¨zü?¨|ü?¨~ü?¨ü?¨ü?¨ü?¨ü?¨ü?¨ü?¨ü?¨ü?¨°ü?¨²ü?¨´ü?¨¶ü?¨¸ü?¨ºü?¨¼ü?¨½ü?¨¾ü?¨¿ü?¨Ðü?¨Ñü?¨Òü?¨Óü?¨Ôü?¨Õü?¨Öü?¨×ü?¨Øü?¨Ùü?¨Úü?¨Ûü?¨Üü?¨Ýü?¨Þü?¨ßü?¨àü?¨áü?¨âü?¨ãü?¨äü?¨æü?¨èü?¨éü?¨ëü?¨ìü?¨íü?¨îü?¨ïü?¨ ý?¨"ý?¨$ý?¨%ý?¨&ý?¨'ý?¨(ý?¨)ý?¨*ý?¨+ý?¨,ý?¨-ý?¨.ý?¨/ý?¨#ý?¨Aý?¨Bý?¨Dý?¨Fý?¨Gý?¨Hý?¨Iý?¨Jý?¨Lý?¨Ný?¨pý?¨rý?¨tý?¨vý?¨xý?¨yý?¨zý?¨{ý?¨|ý?¨~ý?¨ý?¨ý?¨ý?¨ý?¨ý?¨ý?¨ý?¨ý?¨ý?¨ý?¨¡ý?¨£ý?¨¥ý?¨§ý?¨©ý?¨«ý?¨¬ý?¨­ý?¨®ý?¨Àý?¨Âý?¨Äý?¨Æý?¨Èý?¨Êý?¨Ìý?¨Îý?¨ðý?¨òý?¨ôý?¨öý?¨÷ý?¨øý?¨ùý?¨úý?¨ûý?¨üý?¨ýý?¨ÿý?¨þ?¨þ?¨þ?¨þ?¨þ?¨þ?¨þ?¨þ?¨þ?¨?¨þ?¨þ?¨þ?¨ þ?¨"þ?¨#þ?¨$þ?¨%þ?¨&þ?¨(þ?¨*þ?¨+þ?¨,þ?¨-þ?¨.þ?¨/þ?¨#þ?¨Aþ?¨Bþ?¨Cþ?¨Eþ?¨ß#¨#¨#¨#¨#¨#¨#¨#¨#¨#¨Þ#¨ #¨Gþ?¨Hþ?¨Jþ?¨Lþ?¨Nþ?¨`þ?¨bþ?¨dþ?¨fþ?¨hþ?¨jþ?¨lþ?¨nþ?¨ þ?¨¢þ?¨¤þ?¨¦þ?¨¨þ?¨ªþ?¨¬þ?¨­þ?¨®þ?¨¯þ?¨'
^[[?1;2c^[[?1;2c
I do not understand this low level framebuffer example so I am a bit lost right now. The web is also not revealing any docs. Some basic hints about what's happening here would be enough.
I am also using xorg server.
The file you are invoking seems not to be a valid ELF executable, bash tries to process it as a bash script and fails. You can check for sure by using file command, e.g. file modeset.
Check for the errors during your GCC build. Note that you try to compile modeset.h, not modeset.c.

C to NASM conversion

I'm trying to find a way to convert simple C code to NASM assembly. I have tried using objconv and downloaded and unzipped and built it since I am using a MAC; however, it doesn't seem to be working. I keep getting "-bash: objconv: command not found". Does anyone know another way or can help me solve the -bash error.
Bash is the program that takes the words you type in a terminal and launches other programs. If it is reporting an error, it is because it cannot find the program you want to run (at least in this case).
You need to either find a pre-packaged installation of objconv, or you need to do the work to "integrate" your copy of objconv yourself.
If you can identify the executable you want to run (probably called objconv) you need to add that to your path. The easiest way (if it is just for you) is to verify that your ~/.bashrc or ~/.bashprofile has a line that looks something like
PATH=$PATH:${HOME}/bin
Don't worry if it doesn't look exactly the same. Just make sure there's a ${HOME}/bin or ~/bin (~ is the short version of ${HOME}).
If you have that then type the commands
cd ~/bin
ln -fs ../path/to/objconv
and you will create a soft link (a type of file) in your home binary directory, and the program should be available to the command line.
If you create the file, and nothing above has any errors, but it is not available to the command line, you might need to set the executable bit on your "real" (not link) copy of objconv.
If this doesn't work, by now you should be well primed for a better, more specific question.
If you have gcc installed, try gcc -masm=intel -S source.c to generate assembly files in a syntax very similar to that of MASM.

How do I check /etc/network/interfaces file grammar and test it in C code?

I have a file ("interfaces_new" like /etc/network/interfaces) that I have to test.
Tests concerns File grammar and if I can detect if the settings are correct by testing, it is only better.
I searched and I fell on the ifup command that seems to do everything I want.
The trouble is that I do not want to call system in my C code, so I try to retrieve the sources of ifupdown.
I do not even succeeded, many result indicating to me that a script ifup on most system. On my Debian 7.1.0, it is a EFL binary.
What comes to my questions:
* Is it a usable tool in C code which allows to parse the grammar of a file / etc / network / interfaces?
* Is there a doc listing all the valid options? ifup man gives nothing (or I look bad :/ ), the idea being to make my own parser.
* How to get the source code of the ifup command to Debian 7.1.0?
As I originally commented:
You should read and learn more about parsing. Read interfaces(5) to understand the format of /etc/network/interfaces
The ifup command is from ifupdown package, so get its source code.
At last, you simply could popen(3) the following command
ifup --verbose --no-act --force --all --interfaces=/tmp/interfaces_new
assuming your file is in /tmp/interfaces_new.
(Warning, I did not test my suggestion, leaving that to you)

Syntax error while declaring string array in shell script

I have a shell script to convert WordPress Plugin readme files between .txt format and .md. It works perfectly fine in Mac terminal.
When I tried to run the shell script in Ubuntu, the following line
PLUGINMETA=("Contributors" "Donate link" "Donate Link" "Tags" "Requires at least" "Tested up to" "Stable tag" "License" "License URI")
throws the following syntax error.
Syntax error: "(" unexpected (expecting "}")
That particular line is just declaring a list of string variables. I am not sure why it is generating a syntax error. Can someone kindly tell me which there is an error?
Edit:
The full source code of the file is available at https://github.com/sudar/wp-plugin-in-github/blob/master/readme-convertor.sh
I have picked up the relevant line and added above. Not sure if I have to include more lines.
Damn!!, I seem to be using the wrong shell. I was executing it with sh, instead of bash.
In mac, sh is mapped to bash, but it is not in Ubuntu.

Beginner Doing K&R

I'm just starting programming and going through K&R to try and learn C. I've gotten to the section on command line arguments (5.10) but now I'm stumped. Every time I try and open a program I've written with command line arguments I'm told that file X, X being the argument, doesn't exist.
`gcc -o find find.c
open find test
The file /Documents/Learning_C/test does not exist.`
Any suggestions? Thanks
What system are you on? In Unix/Linux you compile & run your executable via:
gcc -o find find.c
./find test
As others have noted, when you prefix your binary with "./", there wont be any naming conflicts. However, if you made find accessible in your $PATH, you might have some conflicts with find and test--standard programs with most *nix distributions... Maybe you could choose more specific names (i.e. ./myFind testArg)
Try giving your output executable a different name.
I suspect your executing the system find command which is looking for a directory called 'test'.
Or try forcing it by executing
./find toto
Edit: Prepending the ./ to the command is important because it tells the shell to execute the find in the current directory as opposed to the first 'find' that exists in your PATH. It is normally recommended that you don't have . (the current directory) in your PATH for security reasons.
HTH
P.S. Forgot to say good one for working through K&R. I just finished doing the same after working in C for thirty years and it was good to get back and refresh the mind!
Instead of making us all individually guess what exactly you're doing wrong, perhaps you should paste the program you're using for the illustration mentioned ?

Resources