DEV Community

Hosni Zaaraoui
Hosni Zaaraoui

Posted on

The day I realized the shebang matters

First I ran:

chmod +x hello.py
./hello.py
Enter fullscreen mode Exit fullscreen mode

and got:

Permission denied

Enter fullscreen mode Exit fullscreen mode

I thought the 755 bit was enough, but the real issue was the shebang line.

If the first line of a script doesn't point to a valid interpreter, the kernel tries to execute the file directly and fails with permission denied.

The fix? Add a proper shebang:

!/usr/bin/env python3

or point to the exact path:

!/usr/bin/python3

Then run chmod +x hello.py again.

Now it works.
Lesson: Always double-check the shebang, especially when moving scripts between machines.

Have you run into this before?

Top comments (0)