开发者

Exclude specific filename from shell globbing

开发者 https://www.devze.com 2022-12-27 03:52 出处:网络
I want to excluse a specific filename (say, fubar.log) from a shel开发者_如何学Gol (bash) globbing string, *.log. Nothing of what I tried seems to work, because globbing doesn\'t use the standard RE s

I want to excluse a specific filename (say, fubar.log) from a shel开发者_如何学Gol (bash) globbing string, *.log. Nothing of what I tried seems to work, because globbing doesn't use the standard RE set.

Test case : the directory contains

fubar.log
fubaz.log
barbaz.log
text.txt

and only fubaz.log barbaz.log must be expanded by the glob.


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


Why don't you use grep? For example:

ls |grep -v fubar|while read line; do echo "reading $line"; done;

And here is the output:

reading barbaz.log reading fubaz.log reading text.txt

0

精彩评论

暂无评论...
验证码 换一张
取 消