当我尝试阻止通配符扩展到以下脚本时,它不起作用。例如在我输入的shell中:(我也尝试过\ * .m,“*。m”)
$ getLargeNumFiles.sh $(pwd) '*.m'
我得到了
$ myDirectory
$ file1.m file2.m file3.m
$ find: paths must precede expression
$ Usage: find [-H] [-L] [-P] [path...] [expression]
$ 0 #The result of my function. Found 0 .m files. Should be 3.
getLargeNumFiles.sh
#!/bin/bash
# Syntax
# getLargeNumFiles [folderPath][ext]
# [folderPath] The path of the folder to read.
# To use at folder to search: $(pwd)
function largeRead()
{
numFiles=0
while read line1; do
#echo $line1
((numFiles++))
done
echo $numFiles
}
folderPath=$1
ext=$2
echo $folderPath
echo $ext
find $folderPath -name $ext | largeRead
答案 0 :(得分:2)
将变量放在引号中以防止扩展变量后的通配符扩展:
find "$folderPath" -name "$ext" | largeRead