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

Mavershang
  • 1,224
  • 2
  • 14
  • 25

2 Answers2

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
anubhava
  • 713,503
  • 59
  • 514
  • 593
1

You can use ->

files=`ls $data_dir | grep -v 08142014`
dganesh2002
  • 1,657
  • 1
  • 21
  • 27