Bash程序,用于使用不显示任何数字的函数计算目录中某些类型的文件
当用户输入文件名作为参数时,我的程序需要在目录中搜索所有未隐藏的文件,并查找其权限,如下所示:Bash程序,用于使用不显示任何数字的函数计算目录中某些类型的文件,bash,shell,Bash,Shell,当用户输入文件名作为参数时,我的程序需要在目录中搜索所有未隐藏的文件,并查找其权限,如下所示: ./search.sh file* 然后显示具有该名称和特定权限的文件数。问题是,当我输入一个文件名时,程序根本不显示任何数字。 任何帮助都将不胜感激 #!/bin/bash oRE() { find . -type f -readable -executable -name "$1" | wc -l } nonEx() { num=0 num=$(find . -type f -n
./search.sh file*
然后显示具有该名称和特定权限的文件数。问题是,当我输入一个文件名时,程序根本不显示任何数字。
任何帮助都将不胜感激
#!/bin/bash
oRE()
{
find . -type f -readable -executable -name "$1" | wc -l
}
nonEx()
{
num=0
num=$(find . -type f -name "$1" | wc -l)
if [[ $num -eq 0 ]];
then
echo 1
else
echo $num
fi
}
dir()
{
find "$1" -maxdepth 0 -type d | wc -l
}
oR()
{
find . -type f -readable -name "$1" | wc -l
}
tByt()
{
wc -c < "$1"
}
if [[ "$#" -eq 1 ]];
then
echo normal, readable, and executable : $(oRE "$1")
echo does not exist : $(nonEx "$1")
echo directory : $(dir "$1")
echo normal and readable : $(oR "$1")
echo total bytes in normal files : $(tByt "$1")
fi
脚本的命令行将作为单独的参数扩展到当前目录中的任何匹配文件。如果有多个参数,由于if语句,脚本不会执行任何操作。尝试引用参数
“file*”
谢谢你的回复。我已经像你说的那样试过了,但是没有用。你可能也需要在你的程序中引用不同的$1
,作为“$1”
同样的东西,没有数字。你会得到任何输出吗?如果没有,那么你的If测试不起作用,你应该首先开始调试。你需要在nonEx中的“$1”
之前添加-name
。我添加了-name
,现在我得到了一些数字,让我编辑代码并发布我得到的结果。如果$1包含一个不存在的文件名,这就是问题:wc-c<“$1”
normal, readable, and executable : 1
does not exist : 2
find: `sample*': No such file or directory
directory : 0
normal and readable : 2
./search.sh: line 32: sample*: No such file or directory
total bytes in normal files :