【问题标题】:How to Run a For Loop excluding certain filenames in PuTTY Terminal (SSH connection)?如何在 PuTTY 终端(SSH 连接)中运行排除某些文件名的 For 循环?
【发布时间】:2016-03-02 19:50:37
【问题描述】:

在 SSH PuTTY 连接中,我有一个包含一堆文件的目录 - 我想在 FOR 循环操作中排除其中一些文件 - 具体来说,我想排除任何包含“Parrot”或“ Tiger”在他们的文件名中 - 下面给出了我正在寻找的文件列表。

ls Zoo_Animals*sas |grep -vi Parrot |grep -vi Tiger

对于上下文,通常文件名会显示为 Zoo_Animals_Monkey_07.sasZoo_Animals_Lion_12.sas, 等。

所以,如果我想为所有动物运行命令,我通常会使用 Unix:

for file in Zoo_Animals*.sas; do <command here> "$file"; done

但是,我似乎无法弄清楚如何在排除 Tigers 和 Parrots 文件的同时运行此 FOR 循环。

任何帮助将不胜感激!

【问题讨论】:

  • 人工查找,查看选项-exec

标签: loops for-loop ssh terminal putty


【解决方案1】:

使用 $() 将您的第一个命令嵌入到第二个命令中

for f in $(ls Zoo_Animals*.sas |grep -vi Parrot |grep -vi Tiger); do echo $f; done

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-22
    • 1970-01-01
    • 1970-01-01
    • 2018-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多