小编xta*_*odi的帖子

查找和变量的问题

我尝试了以下不同的变体,但似乎没有任何效果。基本上当find被执行时似乎什么都没有发生。下面我展示了我的 bash 函数代码和运行时的输出。

我有兴趣了解下面的代码会发生什么,以及为什么它不像我明确键入命令时那样表现。

我还被告知我将无法访问rgrep我将要处理的某些盒子,因此我尝试使用这种方法来获取代码等的通用解决方案。

function findin() {

if [ -z $1 ] ; then

    echo "Usage: findin <file pattern> <<grep arguments>>"
    return 1

fi

fIn[1]=$1

shift
fIn[2]="$@"

echo -- "${fIn[1]}"
echo -- "'${fIn[2]}'"

find -type f -name "'${fIn[1]}'" -print0 | xargs -0 grep --color=auto ${fIn[2]}
}
Run Code Online (Sandbox Code Playgroud)

输出是:

$ ls
Server.tcl  Server.tcl~  test.cfg  vimLearning.txt
$ find -type f -name '*.txt' -print0 | xargs -0 grep --color=auto char
x      deletes char under cursor. NNx deletes NN chars …
Run Code Online (Sandbox Code Playgroud)

bash

2
推荐指数
1
解决办法
597
查看次数

标签 统计

bash ×1