tags:

views:

174

answers:

2

Hi, 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 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.

+2  A: 

if you are using bash

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

or without extglob

shopt -s 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
ghostdog74
Thanks! Do you have a solution without extglob?
Alsciende
A: 

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

Roger Choi
Because the glob string is given to a program (logrotate). So I need a glob string.
Alsciende