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
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