shell脚本:错误的解释器:使用pwd时没有此类文件或目录 [英] shell script: bad interpreter: No such file or directory when using pwd
本文介绍了shell脚本:错误的解释器:使用pwd时没有此类文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用for循环遍历目录中的文件,但这会出现.
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
代码:
#!/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
count=0
dir="$PWD"
echo "$dir"
for file in "$dir"/*
do
if [[ -f $file ]]
then
((count++))
fi
done
echo $count
或最简单/最短的解决方案:
or a simplest/shortest solution :
#!/bin/bash
echo "$PWD"
for file; do
[[ -f $file ]] && ((count++))
done
echo $count
这篇关于shell脚本:错误的解释器:使用pwd时没有此类文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文