6

I am trying to run this basic file (ex1.c) with zsh

#include <stdio.h>
int main(int argc, char *argv[])
{
    puts("hello world.");

    return 0;
}

I am getting this error:

zsh: permission denied: ./ex1.c

3 Answers 3

17

You need to compile it first, probably by doing gcc -o ex1 ex1.c.
After compiling it, you will have an executable called ex1, which you can run by doing ./ex1. If you receive another permission denied error, you can make it executable by doing chmod +x ex1.

3
  • 1
    Normally compilers are smart enough to set the executable bit by themselves. Aug 26, 2013 at 14:41
  • 1
    jeez i'm an idiot, I compiled but was running ex1.c not ex1, thanks!
    – eden
    Aug 26, 2013 at 14:59
  • I just needed to do a fresh build and then it ran fine. Nov 28, 2022 at 19:53
4

You can't just run a file with C code. You'll have to first compile it. If you have a gcc compiler available, that's going to be:

gcc -o ex1 ex.c
./ex1
1

It's a C source file, it is not supposed to be run like this, you have to compile it first.

This would do:

make ex1 # Implicit rule which in turn will perform cc -o ex1 ex1.c
./ex1
4

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