gpt4 book ai didi

linux - 禁用通配符扩展到 Bash 脚本不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 09:39:26 25 4
gpt4 key购买 nike

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

最佳答案

将变量放在引号中以防止在扩展变量后进行通配符扩展:

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

关于linux - 禁用通配符扩展到 Bash 脚本不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22973608/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com