0

I have the following function inside a BASH script (running under Ubuntu 12.x), which would copy over a file with spaces inside the file name. It's not working. I've tried many different combinations, with "', with \", etc. How do I get this to work? Thanks!

function copy_docs()
{
    source_directory=/mnt/someplace
    release_directory=/doc/someotherplace

    cp ${source_directory}/"Some file with spaces.txt" ${release_directory}/

}

This is what I'm getting as output (from nearly all permutations):

cp: cannot stat `/mnt/someplace/some': No such file or directory
cp: cannot stat `file': No such file or directory
cp: cannot stat `with': No such file or directory
cp: cannot stat `spaces': No such file or directory
6
  • Try cp ${source_directory}/"Some\ file\ with\ spaces.txt" ${release_directory}/ Commented Aug 19, 2014 at 17:49
  • Do either of your directories have spaces in their names? Commented Aug 19, 2014 at 17:58
  • That did not work. It separates the file into 4 different files, attempting to copy four files (i.e. "Some", "file", "with", "spaces"). Commented Aug 19, 2014 at 17:58
  • I don't see why that should not work. Try running it like this, and post your results: set -x; copy_docs; set +x Commented Aug 19, 2014 at 18:14
  • 1
    Your output cp: cannot stat /mnt/someplace/some: No such file or directory does not match the file name in your cp statement. "Some file with spaces.txt" is not the same as "some file with spaces.txt" which is what your output suggests you are attempting to copy. Commented Aug 19, 2014 at 18:43

1 Answer 1

2
cp ${source_directory}/Some\ file\ with\ spaces.txt ${release_directory}/

or

cp ${source_directory}/'Some file with spaces.txt' ${release_directory}/
2
  • Neither of those worked. Commented Aug 19, 2014 at 20:29
  • 1
    Have you read Timothy Martin's comment posted after your edit? Are you sure there is "Some", not "some"? If yes then add bash --version and type cp to your question. Commented Aug 19, 2014 at 21:42

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.