+ Reply to Thread
Results 1 to 4 of 4

Thread: From windows to Linux paths

 
  1. #1
    Contributing User
    Join Date
    May 2011
    Posts
    166
    Rep Power
    103

    Default From windows to Linux paths

    Hi there

    During the weekend I was bombarded by hundreds of thousands of millions of emails asking how to do the reverse transformation of paths, from windows to Linux. I've got the following script (called windows_path):

    Code:
    #!/bin/bash  
    
    server_name=${@//\\/\/}
    
    projects_name=/mnt/server/projects 
    quotes_name=/mnt/server/quotes  
    
    server_name=${current_dir/Z:/$projects_name} 
    server_name=${server_name/Y:/$quotes_name}  
    
    echo $server_name
    However there are a couple of things to be aware of. First, this script wants the windows path as a parameter (in my case it would be usually pasted from an email). But although it works fine doing a straight invocation from the command line ...

    Code:
     pabloa$ windows_path Y:\Batch 6 - June 24 2011
    /mnt/server/quotes/Batch 2 - June 24 2011
    ... most of the time I want the result to be passed onto some other command, and then it breaks:

    Code:
     pabloa$ cd $(windows_path Y:\Batch 6 - June 24 2011)
    bash: cd: /mnt/servidor/quotes/Batch: No such file or directory
    So we need to "protect" the result with quotation marks. Then it works fine:

    Code:
    
    pabloa$ cd "$(windows_path Y:\Batch 6 - June 24 2011)"
    pabloa$ pwd
    /mnt/servidor/quotes/Batch 6 - June 24 2011
    I've tried to solve this slight inconvenience replacing echo $server_name with echo ${server_name// /\ } and even echo ${server_name// /\\ } to no avail. Maybe someone out there knows of a good way of dealing with this.

    By the way, a very good source of information for the string substitutions I've done in this and the previous scripts can be found here: Manipulating Strings, highly enjoyable reading.

    Cheers.
    P.

  2. #2
    Contributing User
    Join Date
    May 2011
    Posts
    166
    Rep Power
    103

    Default Re: From windows to Linux paths

    Following the thrilling saga of working with Windows paths under Linux, here there is an extra twist that I'm sure will be appreciated by the masses.

    A worthy addition to the script posted earlier is this:
    Code:
    echo $server_name
    # add the following
    cd "$server_name"
    bash
    

    And then after running the script, we will be placed in the directory given as parameter. I couldn't find other way of doing this. There is no way (that I could find) of staying in the new directory when the script returns.

    Cheers.
    P.

  3. #3
    Senior Member Cotty's Avatar
    Join Date
    Nov 2010
    Location
    Caracas, Venezuela
    Age
    56
    Posts
    728
    Rep Power
    400

    Default Re: From windows to Linux paths

    ...I was bombarded by hundreds of thousands of millions of emails...
    Loved that...

  4. #4
    Contributing User
    Join Date
    May 2011
    Posts
    166
    Rep Power
    103

    Default Re: From windows to Linux paths

    Quote Originally Posted by Cotty View Post
    Loved that...
    ... and I've read every single one of them!

    Cheers.
    P.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •