openSUSE Forums > Archives > SF Archives > ARCHIVES - Programming & Scripting » Bash Xargs With Cp Dies On Directory Names Containing Brackets

Go Back   openSUSE Forums > Archives > SF Archives > ARCHIVES - Programming & Scripting
Forums FAQ Members List Search Today's Posts Mark Forums Read


ARCHIVES - Programming & Scripting A place to discuss website design, programming, shell scripts, etc

 
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-Jan-2008, 17:20
Sandor Laza
Guest
 
Posts: n/a
Thumbs up

This might be something really trivial, but drives me mad...

Please copy the following little script into a shell file and run it!

#dont' worry about these lines, just setting up the environment I heve here...
mkdir ./test\ \(\ something\ \)
touch ./test\ \(\ something\ \)/a.txt
echo ./test\ \(\ something\ \) > file_list
DIR=`cat ./file_list`


#Here is the problem:
echo -ne $DIR/a.txt '\x00' $DIR/b.txt | xargs -0 -n2 cp

#I receive the following error message:
#cp: cannot stat `./test ( something )/a.txt ': No such file or directory

Any idea why the cp command does not work???

Any help would be appreciated!!


Sandor Laza
  #2 (permalink)  
Old 05-Jan-2008, 17:31
ken_yap
Guest
 
Posts: n/a
Default

Try:

echo -ne $DIR/a.txt'\x00'$DIR/b.txt | xargs -0 -n2 cp
  #3 (permalink)  
Old 05-Jan-2008, 18:16
ken_yap
Guest
 
Posts: n/a
Default

A much simpler solution might be:

cp "$DIR/a.txt" "$DIR/b.txt"
  #4 (permalink)  
Old 06-Jan-2008, 10:45
Sandor Laza
Guest
 
Posts: n/a
Default

[qu ote name='ken_yap' date='Jan 6 2008, 01:16 AM' post='221548']
A much simpler solution might be:

cp "$DIR/a.txt" "$DIR/b.txt"
[/quote]


Thank you for the help, it works now! The Quotation marks were really needed becouse the shell collapsed the multiple spaces to one without them...

I always learn something new...

  #5 (permalink)  
Old 06-Jan-2008, 17:39
ken_yap
Guest
 
Posts: n/a
Default

Well actually the quotation marks are required to prevent the shell from breaking up the string into multiple arguments separated by spaces, thus giving cp more than two arguments, none of which are correct.
 

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




 

Search Engine Friendly URLs by vBSEO 3.3.0 RC2