Linux 禁用通配符扩展以使Bash脚本不工作
当我试图阻止通配符扩展到以下脚本时,它不起作用。例如,在shell I类型中:(我还尝试了\*.m,“*.m”) 我得到Linux 禁用通配符扩展以使Bash脚本不工作,linux,bash,Linux,Bash,当我试图阻止通配符扩展到以下脚本时,它不起作用。例如,在shell I类型中:(我还尝试了\*.m,“*.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
$ 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
将变量放在引号中,以防止变量展开后进行通配符展开:
find "$folderPath" -name "$ext" | largeRead
find "$folderPath" -name "$ext" | largeRead