bash - 外壳脚本 : bad interpreter: No such file or directory when using pwd

标签 bash unix pwd

我想用 for 循环遍历目录中的文件,但是出现了这个问题。

echo: bad interpreter: No such file or directory

代码:

#!/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

最佳答案

我遇到了同样的问题。删除 #!/bin/bash 对我有用。 bash所在的地方好像没必要加,因为在系统路径上。

我找到了另一个解决方案 here .改变

#!/bin/bash

对于

#!/usr/bin/bash

关于bash - 外壳脚本 : bad interpreter: No such file or directory when using pwd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15735541/

相关文章:

linux - 从 bash 脚本文件中查找没有目录和扩展名的文件名

linux - AWK 脚本自动从字符串中删除前导 0

c - unix 文件缺少 EOF

bash - shell 内置工具

linux - 如何将当前路径复制到剪贴板?

mysql - Linux SED AWK Sqlite 转储到 MySQL 将以 create table 开头的行上的字符串更改为 varchar

bash - bash 脚本如何在不使用 uudecode 的情况下写出二进制文件?

linux - 使用 bash 时忽略正则表达式

unix - 为什么在这种情况下 curl 失败?

python - 有没有一种干净的方法可以通过 python 检查计算机上是否存在给定用户?