shell script: bad interpreter: No such file or directory when using pwd

Alek picture Alek · Apr 1, 2013 · Viewed 103.1k times · Source

I want to go through the files in a directory with a for loop but this comes up.

echo: bad interpreter: No such file or directory

code:

#!/bin/bash
count=0
dir=`pwd`
echo "$dir"
FILES=`ls $dir`
for file in $FILES
do
 if [ -f $file ]
 then
  count=$(($count + 1))
 fi
done
echo $count

Answer

Marco Navarro picture Marco Navarro · Oct 27, 2013

I had the same problem. Removing #!/bin/bash did the trick for me. It seems that is not necessary to add where bash is located, since it is on the system path.

I found another solution here. Change

#!/bin/bash

for

#!/usr/bin/bash