The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
what is wrong with this tr -d? cleansing_flame UNIX for Dummies Questions & Answers 3 02-06-2008 08:34 AM
What’s wrong with the following? vrn UNIX for Dummies Questions & Answers 8 03-19-2006 05:09 PM
where have i gone wrong? Blip Shell Programming and Scripting 3 01-28-2004 12:43 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-19-2007
Registered User
 

Join Date: Jun 2007
Posts: 4
Stumble this Post!
What am I doing wrong?

I really just mess around in UNIX, for the most part, when I want to get something done. I can usually piece things together by searching for brief how-to's on Google, but the syntax errors in my following .sh file are really confusing me. I've got lots of programming experience in other places, so geek-speak is fine.

If you can't tell what my code is supposed to do, I can explain it, but I feel (even with my errors) it should be clear. Oh, and I am running this through the Terminal on Mac OS X.

Code:
hommv_path="/Applications/Games/Heroes\ of\ Might\ and\ Magic\ V.app/"
move_dir="~/Desktop/"
maps_dir="Contents/Resources/transgaming/c_drive/Program\ Files/Ubisoft/Heroes\ of\ Might\ and\ Magic\ V/"
total_dir=$hommv_path$maps_dir
folder_name="Maps/"
#
#Creates the Maps directory if needed
if [ -d $total_dir$folder_name ];
	then
	echo "Maps folder found.";
else
	cd $total_dir;
	mkdir $folder_name;
	echo "New folder $folder_name created in $total_dir.";
fi
#
#Moves all .h5m files from the move_dir to the Maps folder
cd $move_dir
for file in *.h5m;
	do
	mv $file $total_dir$folder_name;
	echo "Map $file moved to $total_dir$folder_name";
done
#
echo "All maps moved successfully."

Last edited by demonpants; 06-19-2007 at 09:57 AM.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-19-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Stumble this Post!
Quote:
Originally Posted by demonpants View Post
Code:
#Copies all .h5m files from the copy_dir to the Maps folder
cd $copy_dir
for file in '*.h5m';
	do
	mv $file '$total_dir$folder_name';
	echo "Map $file moved to $total_dir$folder_name";
done
#
echo "All maps moved successfully."
1. Are you moving or copying? Comment says copy, code says move.

2. Why do you have mixes of single quotes and double quotes?

3. for file in '*.h5m' would only copy a file called '*.h5m', you don't need those quotes.
Reply With Quote
  #3 (permalink)  
Old 06-19-2007
Registered User
 

Join Date: Jun 2007
Posts: 4
Stumble this Post!
1) I am moving, I messed up on the comment.
2) I have quote mixes left over from trying all different combinations of things to get it to work. So there is absolutely no difference?
3) I had the quotes there because this is where my error is being reported. Here is the error.

Code:
/Users/eli/Desktop/HoMM V Map Mover.sh: line 28: syntax error near unexpected to'en `
'Users/eli/Desktop/HoMM V Map Mover.sh: line 28: `for file in *.h5m;
Line 28 is
Code:
for file in *.h5m;
Reply With Quote
  #4 (permalink)  
Old 06-19-2007
kamitsin's Avatar
Registered User
 

Join Date: Nov 2006
Location: /dev/null
Posts: 177
Stumble this Post!
try this

Code:
for file in '*.h5m'
It should work fine. I am a master at making these kind of mistakes
Reply With Quote
  #5 (permalink)  
Old 06-19-2007
Shell_Life's Avatar
Unix/Informix/4GL/SQL
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Stumble this Post!
Demonpants,
Your problem is related to the spaces in the directory names.
There is no problem with your statement:
Code:
for file in *.h5m
The above will loop through all files that end with ".h5m".
If single or double quotes are used in this case, the shell will
take it literally as "*.h5m".
Reply With Quote
  #6 (permalink)  
Old 06-19-2007
Registered User
 

Join Date: Jun 2007
Posts: 4
Stumble this Post!
Okay, so then how do I eliminate space issues with directory names? When I copy paste using "\ " to represent a space into the Terminal, it works fine. If this isn't how I do it within a shell file, what should I change?
Reply With Quote
  #7 (permalink)  
Old 06-19-2007
Shell_Life's Avatar
Unix/Informix/4GL/SQL
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Stumble this Post!
Try using double quotes around it:
Code:
mv $file "$total_dir$folder_name"
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0