Reputation: 1278
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
Upvotes: 1
Views: 53
Reputation: 785146
You can use:
data_dir="/home/data"
shopt -s extglob
files=($data_dir/!(*08142014*))
for file in "${files[@]}"
do
echo "$file"
done
extglob
you need to use shopt -s extglob
Upvotes: 4