2014-04-09 4 views
0

다음 스크립트로의 와일드 카드 확장을 막으려 고 시도하면 작동하지 않습니다. (. * m, "*하는 .m"\ 나는 또한 시도)Bash 스크립트에 대한 와일드 카드 확장이 작동하지 않음

$ 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 

답변

2
를 얻을 : 셸에서 예를 들어 내가 입력

변수가 확장 된 후에 와일드 카드 확장을 방지하려면 변수를 따옴표로 묶으십시오.

find "$folderPath" -name "$ext" | largeRead 
+0

고마워! 정말 잘됐다! – ABC

관련 문제