Exclude specific filename from shell globbing

后端 未结 2 1140
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-10 13:33

I want to excluse a specific filename (say, fubar.log) from a shell (bash) globbing string, *.log. Nothing of what I tried seems to work, because g

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-10 14:12

    if you are using bash

    #!/bin/bash
    shopt -s extglob
    ls !(fubar).log
    

    or without extglob

    shopt -u extglob
    for file in !(fubar).log
    do
      echo "$file"
    done
    

    or

    for file in *log
    do
       case "$file" in
         fubar* ) continue;;
         * ) echo "do your stuff with $file";;
       esac 
    done
    

提交回复
热议问题