【问题标题】:How to use wildcard to be the variable and give it to a csh script如何使用通配符作为变量并将其提供给 csh 脚本
【发布时间】:2018-09-15 06:48:11
【问题描述】:

我不太清楚如何描述我的问题,所以我只是用一个例子来解释我想做什么。

例子:

一个目录下三个文件

aaa.txt、bbb.txt、ccc.log

我会使用 grep 来检查某个关键字是否在 txt 文件中,就像下面的命令一样。

grep keyword *.txt

我想使用 csh 脚本来做同样的事情。所以我写了一个csh脚本。

test.sh

#!/bin/csh -f
grep 'keyword' $1

那我就这样称呼它。

./test.sh *.txt

它似乎只是对其列表中的第一个文件执行 grep。 如何让 test.sh 遍历每个文件?

【问题讨论】:

  • 您可能会在Unix and Linux SE 得到更好的答案。
  • 我不知道 csh 但是使用 /bin/sh 你只需 grep 'keyword' "$@"
  • 非常感谢,它成功了!

标签: shell csh


【解决方案1】:

试试:

#!/bin/csh -f
grep 'keyword' $argv

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-08
    • 2017-06-16
    • 1970-01-01
    • 1970-01-01
    • 2012-06-06
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    相关资源
    最近更新 更多