Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error: "(" unexpected

Tags:

c++

c

linux

gcc

I am trying to compile code using gcc and run the executable, but it is throwing error:

gcc somefile.c -o somefile

compilation goes through successfully. But, when I try to execute it:

$sh somefile

It results in: Syntax error: "(" unexpected. Among the output files, I dont see somefile.o, but instead, I see somefile.c~

The contents of the file:

#include <stdio.h>
int main(int argc, char *argv[])
{
    printf("hi");
}

Context: I am new to programming in linux, and wanted to start out with simple programs. I am running ubuntu 64 bit on a virtual machine, with gcc, g++, etc installed. After that I created a sample file as mentioned above ("somefile.c"), and tried the steps mentioned above, but could not execute. My goal is to compile and execute a sample C or Cpp code on ubuntu using gcc or g++. Please help.

like image 299
recursion1212 Avatar asked Jun 12 '26 01:06

recursion1212


2 Answers

your somefile is executable binary, it's not shell script. you should execute it by:

$./somefile
like image 56
billz Avatar answered Jun 14 '26 13:06

billz


To execute file you just have to do

$./somefile

sh is used when you've to execute a shell script

like image 37
P0W Avatar answered Jun 14 '26 15:06

P0W



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!