shell script: bad interpreter: No such file or dir

2019-03-19 04:32发布

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

标签: bash unix pwd
7条回答
Bombasti
2楼-- · 2019-03-19 05:23

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.

sed -i 's//\r/\n//\n/g' /path/to/file.sh
查看更多
登录 后发表回答