Reputation: 153
I'm trying to move files from within a bash script,
I have the source and destination saved to variables:
source='/Users/usr/Downloads/Drop/test\ movie.m4v'
dest='/Users/usr/Downloads/Movies/test\ movie.m4v'
And I'm running:
mv $source $dest
I get the output:
usage: mv [-f | -i | -n] [-v] source target
mv [-f | -i | -n] [-v] source ... directory
What am I doing wrong!?
The files I'm moving may or may not contain spaces in their paths. I'm using sed to add the escape char before the space.
Thanks in advance :)
Upvotes: 2
Views: 2105
Reputation: 153
Rather than using escape chars I'm just wrapping my variables in quotes, so:
source='/Users/usr/Downloads/Drop/test movie.m4v'
dest='/Users/usr/Downloads/Movies/test movie.m4v'
mv "$source" "$dest"
Upvotes: 0
Reputation: 47169
There are a bunch of ways to deal with filenames that contain spaces, one quick solution might be to wrap the variables in the mv
command in quotes:
#!/bin/bash
source=/path/to/file\ with\ space
dest=/path/to/file\ with\ space2
mv "$source" "$dest"
Upvotes: 1