Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Exec format error on bash script

📅 2021-Apr-07 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ bash, error ⬩ 📚 Archive

Problem

I had a few repetitive commands that I pasted into a text file and created a Bash script from it. I made the script file executable. When I ran the script, I got this error:

$ ./foobar.sh
Failed to execute process './foobar.sh'. Reason:
exec: Exec format error
The file './foobar.sh' is marked as an executable but could not be run by the operating system.

Solution

The Bash script file was so small and simple that this error stumped me for a moment.

On closer examination, I found that I had mistakenly put a space before the shebang and that was throwing this error:

 #!/bin/bash
^-- space

🤦‍♂️


© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧