Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Search Forums:



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 !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-04-2008
Registered User
 

Join Date: Aug 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
ignoring a dash in file name

so i have a simple file called -x and i need it renamed to x

now i dont understand why when using the most basic methods, only the code
Code:
mv ./-x x

changes the file name while using any other type of escape characters around the dash, such as single/double quotations or backslash, doesnt.

anyone? im completely new to unix and this seems out of the ordinary. im sure there is a very obvious answer to this

shouldnt things like mv /-/x x or mv "-"x x work?
Sponsored Links
    #2  
Old 08-04-2008
Yogesh Sawant's Avatar
Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,211
Thanks: 6
Thanked 17 Times in 16 Posts
mv -x x passes option -x to command mv. that is not what you are intended to do
mv ./-x x does the job - since you mentioned relative path, which solved the "passing option to the command" problem
Sponsored Links
    #3  
Old 08-04-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,653
Thanks: 0
Thanked 7 Times in 7 Posts
Quoting is to prevent interpretation by the shell, whereas option processing is handled by the program itself. The shell strips and discards quotes, so mv doesn't even see a difference between "-"x and -x (and /-/x is, frankly, neither here nor there).
    #4  
Old 08-04-2008
Registered User
 

Join Date: Aug 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
i see, thank both of you for clearing this up for me, it is very much appreciated

im sure ill run into you lot more as i go on and on with unix. im the definition of noob at the moment
Sponsored Links
    #5  
Old 08-04-2008
broli's Avatar
Registered User
 

Join Date: Dec 2007
Location: Argentina
Posts: 215
Thanks: 0
Thanked 0 Times in 0 Posts
and what about using \ ?

mv \-x x <---
Sponsored Links
    #6  
Old 08-04-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,653
Thanks: 0
Thanked 7 Times in 7 Posts
broli: it's the same as quoting; it only prevents interpretation by the shell.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
gethostbyname_r returns NULL when hostname has dash uunniixx IP Networking 12 06-04-2008 01:02 AM
dash after ampersant csecnarf UNIX for Dummies Questions & Answers 2 03-12-2008 02:47 PM
wc of characters in a file ignoring white space sachin.gangadha UNIX for Dummies Questions & Answers 1 12-15-2007 05:13 PM
double-dash options dhinge Shell Programming and Scripting 1 01-10-2007 09:32 PM
How to remove a file with a leading dash '-' in it's name? GSalisbury UNIX for Advanced & Expert Users 3 05-05-2003 11:28 AM



All times are GMT -4. The time now is 04:02 AM.