1

Thank you very much in advance for helping!

I'd like to transform this variable:

win_path=/cygdrive/g/virtual_tours/.archives/vt_template_8_0_15/test_directory_2/panos

into:

win_path_dir=G:/virtual_tours/.archives/vt_template_8_0_15/test_directory_2/panos

This in what I have so far, but it doesn't work. When I echo $win_path it returns nothing (black, empty space)

$win_path=$(echo $i | sed -e 's/\/cygdrive\/g/G\:/g')

Cheers!

4 Answers 4

1

Your approach is good, there is only a little typo:

win_path=$(echo $i | sed -e 's/\/cygdrive\/g/G\:/g')

Do not write $win_path (no $) when defining the value of variable win_path. When you write $win_path the shell expands the value of the variable.

Sign up to request clarification or add additional context in comments.

1 Comment

Do'oh! That was a truly beginners mistake! Thanks!
0

Don't precede the variable with $ when you're defining or setting a variable:

win_path=$(echo $i | sed -e 's/\/cygdrive\/g/G\:/g')

$ causes the string $name to be replaced with the value of variable name, see bash manpage.

Comments

0

If wine is available, winepath is the tool for the job.

Comments

0

Using bash substitution:

prefix=/cygdrive/g
win_path=${winpath/#$prefix/G:}

Note that defining prefix isn't strictly necessary; it just relieves you of the need to escape the directory separators. The following works just fine, although it is slightly less readable:

win_path=${winpath/#\/cygdrive\/g/G:}

1 Comment

It's not strictly necessary; it anchors the pattern to the beginning of the string, so that you don't, e.g., change '/foo/cygdrive/g/other' to '/foo/G:/other'. You could leave it off, and in this instance it would still work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.