Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Directory with space on command line

by mvaline (Friar)
on Feb 05, 2011 at 23:13 UTC ( [id://886452]=note: print w/replies, xml ) Need Help??


in reply to Directory with space on command line

Command line argument parsing is handled by your shell, not by Perl. See the documentation for your shell for details on how it handles single and double quotes.

Unix shell documentation is pretty easy to find. Under Windows, when running CMD.EXE, your options include enclosing the path in double quotes, escaping the space characters, or reverting to DOS-style 8.3 filenames. The new PowerShell is a bit more sophisticated, but enclosing paths in single-quotes is usually correct.

  • Comment on Re: Directory with space on command line

Replies are listed 'Best First'.
Re^2: Directory with space on command line
by JNourse (Initiate) on Mar 13, 2011 at 00:14 UTC

    I am using the CPAN module

    use File::Basename;

    I am working with Ubuntu and using the Terminal application under gnome. The perl instruction I am using is

    my $directname = dirname($ARGV[0]);

    The actual command line varies but here is an example

    perl Get_SQL_Template_file_for_updating.pl '/media/MR23M19P/MySQL Dat +afiles/Dufferin Hi-Lands/ ' 26 DH M

    If I place the Space after the last slash before the single quote all is fine. If I do not, the dirname subroutine assumes that the directory is

    /media/MR23M19P/MySQL Datafiles

    It assumes that the

    MySQL

    is a file name since it ends with a space and ignores the rest of the parameter, but does pick up the other parameters on the command line. Any Assistance will be greatly appreciated.

      I recommend you take a look at the documentation for dirname. The behavior you are experiencing is expected.

      This function is provided for compatibility with the Unix shell command dirname(1) and has inherited some of its quirks. In spite of its name it does NOT always return the directory name as you might expect. To be safe, if you want the directory name of a path use fileparse().
      When using Unix or MSDOS syntax this emulates the dirname(1) shell function which is subtly different from how fileparse() works. It returns all but the last level of a file path even if the last level is clearly a directory. In effect, it is not returning the directory portion but simply the path one level up acting like chop() for file paths.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://886452]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-04-23 12:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found