Question

I have a variable that stores a Unix path, for example:

typeset unixpath=/foo/bar/

And I have to convert it to a DOS path using KornShell (ksh) scripting:

dospath=\\\\foo\\\\bar\\\\
Was it helpful?

Solution

Try:

dospath=`echo $unixpath | sed 's/\//\\\\/g'`

Thanks to David Wolever for reminding me to use a $ to access the value of the variable!

OTHER TIPS

If you have ksh93:

ksh-M 93t 2008-11-04$ unixpath=/foo/bar/            
ksh-M 93t 2008-11-04$ print ${unixpath//\//\\\\\\\\}
\\foo\\bar\\

The AT&T ksh93 for Windows allows you to tag variables for automatic conversion with 'typeset -H':

$ typeset -H home=$HOME && print $home=$HOME C:\users\Henk=/home/Henk

I would have added as a comment to eleven81's answer, but I don't have the points

to make it slightly more readable, how about using an alternative sed delimiter

i.e.

dospath=`echo $unixpath | sed 's./.\\\\.g'`
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top