Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 禁用通配符扩展以使Bash脚本不工作_Linux_Bash - Fatal编程技术网

Linux 禁用通配符扩展以使Bash脚本不工作

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

当我试图阻止通配符扩展到以下脚本时,它不起作用。例如,在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 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