2

I am using the following shell code to move files from one location to another:

for i in [ test1 test2 test3]
do
  mv /home/usr/enabler/$i/*  /home/bin/enabler/consolidate
  echo "moved successfully!!!"
done                                                                               

Running in the bash shell I get the error "Illegal file pattern: Unclosed character class near index 1". I want the loop to go to each folder test1, test2, test3 and move all files present in test1, test2, test3 in destination folder.

ashawley
  • 4,195
  • 1
  • 27
  • 40
vikash
  • 33
  • 5
  • The square brackets don't seem to be at all useful here, why did you put those? Also take care to properly quote your variables. See also http://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-variable – tripleee Apr 25 '17 at 13:26
  • 1
    single line: `mv /home/usr/enabler/{test1,test2,test3}/* /home/bin/enabler/consolidate` – Shakiba Moshiri Apr 25 '17 at 13:46

1 Answers1

2

Fix your script that way:

for i in test1 test2 test3
do
  mv /home/usr/enabler/"$i"/*  /home/bin/enabler/consolidate
  echo "moved successfully!!!"
done

This is exactly that you want!!

chepner
  • 497,756
  • 71
  • 530
  • 681