0

I'm using variables in bash script to hold folder names (to iterate over multiple folders). I'd like to copy files from one to another, the files exist in source directory. Folders and filenames contain spaces, so I must use double quote.

For instance:

#!/bin/bash
inpath="~/foo bar/"
outpath="~/temp basket/
cp "$inpath*" "$outpath" 

The copy fails as: '~/foo bar/*' No such file or directory

Is there any consistent way to do that?

1 Answers1

2

Only quote the parts you don't want expanded or split:

inpath=~/'foo bar'
outpath=~/'temp basket'
cp -- "$inpath/"* "$outpath"
melpomene
  • 79,257
  • 6
  • 70
  • 127