Bash Script (!#) Shebang Issue (Vagrant, Linux, Windows)

Now, just found this issue yesterday. This happen on Vagrant that have Linux guest machine and using Windows as host machine.

Our shebang script suddenly give us

: No such file or directory

In one of the developer machine. But it works normally on the others. So I try to take a look at it.

The error is happening on one of the machine that is using Windows as the host machine and it does not happening on Linux / Mac’s. So it must be Windows thing right?

Judging from the editor – I cannot see any differences from the shebang lines below.


#!/usr/bin/env php
#!/usr/bin/env node

But suddenly I remember that Windows use CRLF and Linux use LF as line endings.

Never heard of such case in shebang script, I try to prove it by creating a simple hello world that is using proper LF line ending and it works properly.

So yeah if you got : No such file or directory error on your shebang script and you use Vagrant and have multi-OS developers – check your line-ending 🙂

The cause:

  1. Using Vagrant
  2. Using Linux as Guest Machine
  3. Using Windows
  4. Have some shebang scripts
  5. Does not properly set .gitattributes to properly resolve line endings

The fix:

  1. Properly set .gitattributes to properly force line ending – we use text eol=lf (see Github Article about dealing with Line Endings)
  2. Temporary fix to use dos2unix tool to convert the file line-ending