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):
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:#!/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
... most of the time I want the result to be passed onto some other command, and then it breaks:Code:pabloa$ windows_path Y:\Batch 6 - June 24 2011 /mnt/server/quotes/Batch 2 - June 24 2011
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) bash: cd: /mnt/servidor/quotes/Batch: No such file or directory
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.Code:pabloa$ cd "$(windows_path Y:\Batch 6 - June 24 2011)" pabloa$ pwd /mnt/servidor/quotes/Batch 6 - June 24 2011
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.


Reply With Quote


