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
In my case the bash script was created on a Windows PC which added a carriage return character in front of every line feed. \x0D\x0A instead of just \x0A. I replaced all the CRLF with just LF using the
sed
and my script works now.