bash copy with variable
Posted
by zaf
on Stack Overflow
See other posts from Stack Overflow
or by zaf
Published on 2010-05-27T15:02:34Z
Indexed on
2010/05/27
15:21 UTC
Read the original article
Hit count: 169
I'm trying to copy files to the current directory using a bash script.
In order to handle paths that need escaping a variable is used that is escaped and then supplied to the cp command.
The cp command is complaining with:
usage: cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file
cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... target_directory
I know what that means but I cannot understand why that happens.
Here is the code:
z="/a/b/c d e f.txt"
y=`printf %q "$z"`
cp $y x.txt # not working as expected
echo cp $y x.txt # output is "cp /a/b/c\ d\ e\ f.txt x.txt"
© Stack Overflow or respective owner