public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Access windows environment variable via cygwin
@ 2017-05-12  2:07 ChampS
  2017-05-12  3:07 ` Eliot Moss
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: ChampS @ 2017-05-12  2:07 UTC (permalink / raw)
  To: cygwin

Hi,

I want to use Cygwin to access all Windows applications installed on my 
Windows 7 system. The Problem is that Windows is using spaces in its 
environment variable 'Path' and Cygwin can not handle the spaces. Is 
there a way to use the Windows environment variable 'Path' even with 
spaces in it? For Example I want to start x86 sbt via Cygwin, then I 
will get the following error message: "/cygdrive/c/Program Files 
(x86)/sbt/bin/sbt: line 61: /sbt-launch-lib.bash: No such file or 
directory". But when I try it with the default Windows cmd it works.

Thought about something like iterating over the 'Path' environment 
variable in bashrc and adapt the strings to fit for Cygwin. But I don't 
know how I can access the Windows environment variables and how I could 
provide the adapted environment variable to Cygwin.

Someone an idea how I could solve this issue?

Kind regards,
Ben

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Access windows environment variable via cygwin
  2017-05-12  2:07 Access windows environment variable via cygwin ChampS
@ 2017-05-12  3:07 ` Eliot Moss
  2017-05-12  5:07   ` Larry Hall (Cygwin)
  2017-05-12  3:09 ` Brian Inglis
  2017-05-12 15:46 ` cyg Simple
  2 siblings, 1 reply; 8+ messages in thread
From: Eliot Moss @ 2017-05-12  3:07 UTC (permalink / raw)
  To: cygwin

On 5/11/2017 9:14 PM, ChampS wrote:
> Hi,
>
> I want to use Cygwin to access all Windows applications installed on my Windows 7 system. The
> Problem is that Windows is using spaces in its environment variable 'Path' and Cygwin can not handle
> the spaces. Is there a way to use the Windows environment variable 'Path' even with spaces in it?
> For Example I want to start x86 sbt via Cygwin, then I will get the following error message:
> "/cygdrive/c/Program Files (x86)/sbt/bin/sbt: line 61: /sbt-launch-lib.bash: No such file or
> directory". But when I try it with the default Windows cmd it works.
>
> Thought about something like iterating over the 'Path' environment variable in bashrc and adapt the
> strings to fit for Cygwin. But I don't know how I can access the Windows environment variables and
> how I could provide the adapted environment variable to Cygwin.
>
> Someone an idea how I could solve this issue?

Yeah, spaces are hell in paths in the Posix/Linux kind of world.

What you need is to "protect" the spaces with \ or have them inside a quoted string.
Also, items in a path need to be separated by : and not ; ....

This mostly has to do with understanding how strings, quoting, etc., work in
the Unix world and for bash in particular.  Over time I have developed methods
that work with these things that have space in them. For example, to add something
to the end of PATH:

PATH="${PATH}:/my/new/thing"

Here the quotes are important!  And they need to be " quotes not ' quotes!
( ' quotes would not allow ${PATH} to be expanded, while " quotes do allow that.)
Etc.

Regards - Eliot Moss

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Access windows environment variable via cygwin
  2017-05-12  2:07 Access windows environment variable via cygwin ChampS
  2017-05-12  3:07 ` Eliot Moss
@ 2017-05-12  3:09 ` Brian Inglis
  2017-05-12 13:27   ` Andrey Repin
  2017-05-12 14:23   ` Jim Reisert AD1C
  2017-05-12 15:46 ` cyg Simple
  2 siblings, 2 replies; 8+ messages in thread
From: Brian Inglis @ 2017-05-12  3:09 UTC (permalink / raw)
  To: cygwin

On 2017-05-11 19:14, ChampS wrote:
> I want to use Cygwin to access all Windows applications installed on
> my Windows 7 system. The Problem is that Windows is using spaces in
> its environment variable 'Path' and Cygwin can not handle the spaces.
> Is there a way to use the Windows environment variable 'Path' even
> with spaces in it? For Example I want to start x86 sbt via Cygwin,
> then I will get the following error message: "/cygdrive/c/Program
> Files (x86)/sbt/bin/sbt: line 61: /sbt-launch-lib.bash: No such file
> or directory". But when I try it with the default Windows cmd it
> works.

Cygwin has no problem with paths containing spaces.
Windows cmd will launch Windows programs in the registry even if their 
bin directories are not in your PATH, as will cygstart; otherwise  
Cygwin requires either that bin directories are in your PATH, or that 
you specify the full path to the executable when you run any program, 
and if there any spaces or other shell special characters in the full 
path, they needs quoted; quoting can use prefix \ or quotes e.g.
	/cygdrive/c/Program\ Files\ \(x86\)/sbt/bin/sbt
	'/cygdrive/c/Program Files (x86)/sbt/bin/sbt' as in ls or
	"/cygdrive/c/Program Files (x86)/sbt/bin/sbt". 

> Thought about something like iterating over the 'Path' environment
> variable in bashrc and adapt the strings to fit for Cygwin. But I
> don't know how I can access the Windows environment variables and how
> I could provide the adapted environment variable to Cygwin.

Cygwin automatically converts all directories in your PATH 
when you start a process.
From bash, echo "$PATH", to see what Cygwin has done.
Base utility cygpath -p allows you to do this on your own Windows 
environment variables like $CLASSPATH etc. as long as you properly 
quote the conversion e.g. 

$ CLASSPATH='C:\Program Files\Java;C:\Program Files (x86)\Java'
$ cp="$(cygpath -Up "$CLASSPATH")"
$ echo "$cp"
/proc/cygdrive/c/Program Files/Java:/proc/cygdrive/c/Program Files (x86)/Java
 
> Someone an idea how I could solve this issue?

If your scripts use environment variables, they should be careful 
to enclose uses of those variables in double quotes "$VAR".

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Access windows environment variable via cygwin
  2017-05-12  3:07 ` Eliot Moss
@ 2017-05-12  5:07   ` Larry Hall (Cygwin)
  0 siblings, 0 replies; 8+ messages in thread
From: Larry Hall (Cygwin) @ 2017-05-12  5:07 UTC (permalink / raw)
  To: cygwin

On 05/11/2017 10:44 PM, Eliot Moss wrote:
> On 5/11/2017 9:14 PM, ChampS wrote:
>> Hi,
>>
>> I want to use Cygwin to access all Windows applications installed on my
>> Windows 7 system. The
>> Problem is that Windows is using spaces in its environment variable 'Path'
>> and Cygwin can not handle
>> the spaces. Is there a way to use the Windows environment variable 'Path'
>> even with spaces in it?
>> For Example I want to start x86 sbt via Cygwin, then I will get the
>> following error message:
>> "/cygdrive/c/Program Files (x86)/sbt/bin/sbt: line 61:
>> /sbt-launch-lib.bash: No such file or
>> directory". But when I try it with the default Windows cmd it works.
>>
>> Thought about something like iterating over the 'Path' environment
>> variable in bashrc and adapt the
>> strings to fit for Cygwin. But I don't know how I can access the Windows
>> environment variables and
>> how I could provide the adapted environment variable to Cygwin.
>>
>> Someone an idea how I could solve this issue?
>
> Yeah, spaces are hell in paths in the Posix/Linux kind of world.

Really, they are just as bad in the Windows world, as one quickly finds out
if you're at a command prompt.  Just as spaces in path and file names need
to be escaped in POSIX/Linux/Unix and like environments, Windows requires
the same thing.  It just uses different syntax for doing so.  But that's
OK.  Without all this complication, using computers would be no fun at all.
;-)

-- 
Larry

_____________________________________________________________________

A: Yes.
 > Q: Are you sure?
 >> A: Because it reverses the logical flow of conversation.
 >>> Q: Why is top posting annoying in email?

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Access windows environment variable via cygwin
  2017-05-12  3:09 ` Brian Inglis
@ 2017-05-12 13:27   ` Andrey Repin
  2017-05-12 14:18     ` Brian Inglis
  2017-05-12 14:23   ` Jim Reisert AD1C
  1 sibling, 1 reply; 8+ messages in thread
From: Andrey Repin @ 2017-05-12 13:27 UTC (permalink / raw)
  To: Brian Inglis, cygwin

Greetings, Brian Inglis!

>> Someone an idea how I could solve this issue?

> If your scripts use environment variables, they should be careful 
> to enclose uses of those variables in double quotes "$VAR".

Correction: You should always use proper quoting, even if you 100% know the
variable content is "safe", unless the results of not using quoting are
actually desired.


-- 
With best regards,
Andrey Repin
Friday, May 12, 2017 15:22:17

Sorry for my terrible english...


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Access windows environment variable via cygwin
  2017-05-12 13:27   ` Andrey Repin
@ 2017-05-12 14:18     ` Brian Inglis
  0 siblings, 0 replies; 8+ messages in thread
From: Brian Inglis @ 2017-05-12 14:18 UTC (permalink / raw)
  To: cygwin

On 2017-05-12 06:23, Andrey Repin wrote:
>>> Someone an idea how I could solve this issue?
>> If your scripts use environment variables, they should be careful 
>> to enclose uses of those variables in double quotes "$VAR".
> Correction: You should always use proper quoting, even if you 100% know the
> variable content is "safe", unless the results of not using quoting are
> actually desired.

There's lots of contexts where you don't need quoting, as the shell uses the 
variable and contents and does the right thing, but there is no easy way to 
describe this, other than quote where there are shell parameter expansions, 
which may not mean much to many.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Access windows environment variable via cygwin
  2017-05-12  3:09 ` Brian Inglis
  2017-05-12 13:27   ` Andrey Repin
@ 2017-05-12 14:23   ` Jim Reisert AD1C
  1 sibling, 0 replies; 8+ messages in thread
From: Jim Reisert AD1C @ 2017-05-12 14:23 UTC (permalink / raw)
  To: cygwin

On Thu, May 11, 2017 at 9:07 PM, Brian Inglis wrote:

> Cygwin has no problem with paths containing spaces.

That may be somewhat of an oversimplification.  Due to the way we do
backups at work, my Cygwin "root" is installed in a path that contains
spaces.  Most things work OK, but Xwin is unable to automatically run
"xrdb" when it starts up.  This means that my default X program
configurations (xterm , Emacs) are not read.  I have to manually run
xrdb each time I start a new Xwin session.  It's not the end of the
world, but it does require a little extra work each time.

- Jim

-- 
Jim Reisert AD1C, <jjreisert@alum.mit.edu>, http://www.ad1c.us

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Access windows environment variable via cygwin
  2017-05-12  2:07 Access windows environment variable via cygwin ChampS
  2017-05-12  3:07 ` Eliot Moss
  2017-05-12  3:09 ` Brian Inglis
@ 2017-05-12 15:46 ` cyg Simple
  2 siblings, 0 replies; 8+ messages in thread
From: cyg Simple @ 2017-05-12 15:46 UTC (permalink / raw)
  To: cygwin

On 5/11/2017 9:14 PM, ChampS wrote:
> Hi,
> 
> I want to use Cygwin to access all Windows applications installed on my
> Windows 7 system. The Problem is that Windows is using spaces in its
> environment variable 'Path' and Cygwin can not handle the spaces. Is
> there a way to use the Windows environment variable 'Path' even with
> spaces in it? For Example I want to start x86 sbt via Cygwin, then I
> will get the following error message: "/cygdrive/c/Program Files
> (x86)/sbt/bin/sbt: line 61: /sbt-launch-lib.bash: No such file or
> directory". But when I try it with the default Windows cmd it works.
> 
> Thought about something like iterating over the 'Path' environment
> variable in bashrc and adapt the strings to fit for Cygwin. But I don't
> know how I can access the Windows environment variables and how I could
> provide the adapted environment variable to Cygwin.
> 
> Someone an idea how I could solve this issue?
> 

Besides all of the other help already suggested you can also use the 8.3
format of the directory name to remove the spaces from PATH in your
Windows environment variable.  Then Cygwin will not see the spaces
either.  The use of 8.3 format is configurable and you may need to turn
it on for the drive.  Use the "dir /X" cmd.exe command to see if you
have the 8.3 name.

-- 
cyg Simple

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-05-12 14:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-12  2:07 Access windows environment variable via cygwin ChampS
2017-05-12  3:07 ` Eliot Moss
2017-05-12  5:07   ` Larry Hall (Cygwin)
2017-05-12  3:09 ` Brian Inglis
2017-05-12 13:27   ` Andrey Repin
2017-05-12 14:18     ` Brian Inglis
2017-05-12 14:23   ` Jim Reisert AD1C
2017-05-12 15:46 ` cyg Simple

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).