1

Here is my script

data_dir="/home/data" shopt extglob files=!($data_dir/*08142014*) echo ${files[@]} for file in $files[@] do #blabla done 

/home/data contains multiple files with different date info within file name, thus I should be able to get a list of files that does not contain "08142014".

But kept get syntax error. It seems files is just "!(/home/data/08202014)", while I want a list of file names.

Did I miss anything? Thanks

2
  • 1
    Not enough information. Is there only one file matching that pattern, or should there be more? Does ls show you the same? Commented Aug 20, 2014 at 18:23
  • stackoverflow.com/questions/15253702/… Commented Aug 20, 2014 at 18:25

2 Answers 2

4

You can use:

data_dir="/home/data" shopt -s extglob files=($data_dir/!(*08142014*)) for file in "${files[@]}" do echo "$file" done 
  • To set extglob you need to use shopt -s extglob
  • To set array your syntax isn't right
  • Check how array is correctly iterated
Sign up to request clarification or add additional context in comments.

Comments

1

You can use ->

files=`ls $data_dir | grep -v 08142014` 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.