0

For instance, if I have this as input:

F:\my\path\to\File.TXT

I want to get this as output

/f/my/path/to/File.TXT

This should work even if the path doesn't exist, so I can't simply call

cd $P && pwd -P

Edit: I'd like to avoid using sed and awk, since there are simpler commands to achieve this, like tr and Bash built-ins.

Elifarley
  • 1,310
  • 3
  • 16
  • 23
  • possible duplicate of [Windows PATH to posix path conversion in bash](http://stackoverflow.com/questions/13701218/windows-path-to-posix-path-conversion-in-bash) – npostavs May 07 '15 at 16:33

1 Answers1

0

These 2 Bash functions will help:

canondirslashes() { local p; p="$(echo $1 | tr \\ /)" && echo ${p%/}; }

canonpath() { canondirslashes "$( test "${1:1:1}" != : && echo $1 || echo $(echo /${1::1} | tr [A-Z] [a-z])${1:2} )" ; }

Here's an example:

bash-3.1$ P=F:\\my\\path\\to\\File.TXT

bash-3.1$ echo $P
F:\my\path\to\File.TXT

bash-3.1$ canonpath $P
/f/my/path/to/File.TXT
Elifarley
  • 1,310
  • 3
  • 16
  • 23