目前我正在手动搜索三个字符,它们可以是 dir1 dir2 dir3 等中的任何内容
通过 grep -i -r abc dir1
然后
grep -i -r abc dir2
grep -i -r abc dir3
等等
尝试将其自动化并考虑编写一个 shell 脚本,例如 搜索.sh
然后当我想在上述目录中搜索某些内容时,我可以输入我正在搜索的三个字母
例如:运行search.sh $Mid = abc
shell 脚本会执行如下操作:
$mid = Mid;
grep -i -r $mid nab-prep1001 | grep -i -r $mid nab-prep1002 | grep -i -r $mid multi-account-bpay-report | grep -i -r $mid nab-prep1004 | grep -i -r $mid nab-prep100 | grep -i -r $mid nab-prep1006 | grep -i -r $mid nab-prep1007
最佳答案
非常简单的脚本和直接的方法。参数通过 $n
传递,这里 n 是参数的数量 1,2,3 等。
#!/bin/bash
echo "Simple Script"
echo "$1" "$2
输出:
$ ./simple.sh hello world
Simple Script
hello world
关于linux - 带参数运行 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46822327/