public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Program files environmental variables
@ 2021-11-23  9:02 john doe
  2021-11-23  9:52 ` Csaba Raduly
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: john doe @ 2021-11-23  9:02 UTC (permalink / raw)
  To: cygwin

Cygwins,

Is there a way to get the value of PROGRAMFILES(x86) and PROGRAMW6432 in
Bash:

$ echo $PROGRAMFILES; echo "$PROGRAMFILES(x86)"; echo $PROGGRAMW6432
C:\Program Files
C:\Program Files(x86)

$ cmd.exe /C "echo %PROGRAMFILES% %PROGRAMFILES(x86)% %PROGRAMW6432%"
C:\Program Files C:\Program Files (x86) C:\Program Files


PROGRAMFILES works in Bash but not the other two.

I could not find anything relevent in the archive or when googling.

--
John Doe

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

* Re: Program files environmental variables
  2021-11-23  9:02 Program files environmental variables john doe
@ 2021-11-23  9:52 ` Csaba Raduly
  2021-11-23 10:40   ` Lemures Lemniscati
  2021-11-23 13:10 ` Eliot Moss
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Csaba Raduly @ 2021-11-23  9:52 UTC (permalink / raw)
  To: john doe; +Cc: cygwin list

On Tue, 23 Nov 2021 at 10:02, john doe via Cygwin <cygwin@cygwin.com> wrote:
>
> Cygwins,
>
> Is there a way to get the value of PROGRAMFILES(x86) and PROGRAMW6432 in
> Bash:
>

$ env | grep PROGRAMFILES
COMMONPROGRAMFILES=C:\Program Files\Common Files
PROGRAMFILES=C:\Program Files

These are the environment variables visible in my Cygwin environment.

echo "$PROGRAMFILES(x86)" is the equivalent of echo
"${PROGRAMFILES}(x86)" i.e. the value of $PROGRAMFILES, followed by
the fixed string "(x86)"

I tried

$ echo "${PROGRAMFILES(x86)}"
$ echo "${PROGRAMFILES\(x86\)}"

and bash outright refused them ("bad substitution"). So it may not be
possible to have an environment variable with ()s in its name.

Csaba
-- 
You can get very substantial performance improvements
by not doing the right thing. - Scott Meyers, An Effective C++11/14 Sampler
So if you're looking for a completely portable, 100% standards-conformant way
to get the wrong information: this is what you want. - Scott Meyers (C++TDaWYK)

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

* Re: Program files environmental variables
  2021-11-23  9:52 ` Csaba Raduly
@ 2021-11-23 10:40   ` Lemures Lemniscati
  0 siblings, 0 replies; 8+ messages in thread
From: Lemures Lemniscati @ 2021-11-23 10:40 UTC (permalink / raw)
  To: cygwin

On Tue, 23 Nov 2021 10:52:18 +0100, Csaba Raduly via Cygwin
> On Tue, 23 Nov 2021 at 10:02, john doe via Cygwin <cygwin@cygwin.com> wrote:
> >
> > Cygwins,
> >
> > Is there a way to get the value of PROGRAMFILES(x86) and PROGRAMW6432 in
> > Bash:
> >
> 
> $ env | grep PROGRAMFILES
> COMMONPROGRAMFILES=C:\Program Files\Common Files
> PROGRAMFILES=C:\Program Files
> 
> These are the environment variables visible in my Cygwin environment.
> 
> echo "$PROGRAMFILES(x86)" is the equivalent of echo
> "${PROGRAMFILES}(x86)" i.e. the value of $PROGRAMFILES, followed by
> the fixed string "(x86)"
> 
> I tried
> 
> $ echo "${PROGRAMFILES(x86)}"
> $ echo "${PROGRAMFILES\(x86\)}"
> 
> and bash outright refused them ("bad substitution"). So it may not be
> possible to have an environment variable with ()s in its name.


/usr/bin/printenv 'ProgramFiles(x86)'

Lem

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

* Re: Program files environmental variables
  2021-11-23  9:02 Program files environmental variables john doe
  2021-11-23  9:52 ` Csaba Raduly
@ 2021-11-23 13:10 ` Eliot Moss
  2021-11-23 15:15   ` john doe
       [not found] ` <DB9PR08MB6842C067DA1DB291FBD666A0E9609@DB9PR08MB6842.eurprd08.prod.outlook.com>
  2021-11-23 18:07 ` Brian Inglis
  3 siblings, 1 reply; 8+ messages in thread
From: Eliot Moss @ 2021-11-23 13:10 UTC (permalink / raw)
  To: john doe, cygwin

On 11/23/2021 4:02 AM, john doe via Cygwin wrote:
 > Cygwins,
 >
 > Is there a way to get the value of PROGRAMFILES(x86) and PROGRAMW6432 in
 > Bash:
 >
 > $ echo $PROGRAMFILES; echo "$PROGRAMFILES(x86)"; echo $PROGGRAMW6432
 > C:\Program Files
 > C:\Program Files(x86)
 >
 > $ cmd.exe /C "echo %PROGRAMFILES% %PROGRAMFILES(x86)% %PROGRAMW6432%"
 > C:\Program Files C:\Program Files (x86) C:\Program Files
 >
 >
 > PROGRAMFILES works in Bash but not the other two.

PROGRAMW6432 exists in my Cygwin bash, and I know I did not set it
explicitly.  As for the x86 one, parentheses are not allowed in
bash variable names.  In principle one could set up, say,
PROGRAMFILESx86, however no path of that kind is around in my
bash.  It would be possible to read it out and setup the variable.
I found, for example, that this prints out the setting of the
variable (but with other gorp you'd have to edit out):

echo "echo %PROGRAMFILES(x86)%; exit" | cmd

I forget where these are set up - I think in the Cygwin code.
I'm sure someone else will point that out!

Best - Eliot

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

* Re: Program files environmental variables
       [not found] ` <DB9PR08MB6842C067DA1DB291FBD666A0E9609@DB9PR08MB6842.eurprd08.prod.outlook.com>
@ 2021-11-23 15:11   ` john doe
  0 siblings, 0 replies; 8+ messages in thread
From: john doe @ 2021-11-23 15:11 UTC (permalink / raw)
  To: cygwin

On 11/23/2021 10:37 AM, Daniel Abrahamsson wrote:
> John Doe wrote:
>
>> Cygwins,
>>
>> Is there a way to get the value of PROGRAMFILES(x86) and PROGRAMW6432 in
>> Bash:
>>
>> $ echo $PROGRAMFILES; echo "$PROGRAMFILES(x86)"; echo $PROGGRAMW6432
>> C:\Program Files
>> C:\Program Files(x86)
>>
>> $ cmd.exe /C "echo %PROGRAMFILES% %PROGRAMFILES(x86)% %PROGRAMW6432%"
>> C:\Program Files C:\Program Files (x86) C:\Program Files
>>
>>
>> PROGRAMFILES works in Bash but not the other two.
>>
>> I could not find anything relevent in the archive or when googling.
>>
>> --
>> John Doe
>
> We have a script where we use this workaround:
>
> PROGRAMFILES86=$(env | sed -ne 's/^ProgramFiles(x86)=//p' )
>

I never thought using env like this, an alternative using awk:

$ env | awk -F= '/^ProgramFiles\(x86\)/{print $2}'
C:\Program Files (x86)


printenv is even better! :)

Thanks all for your input much appreciated.

--
John Doe

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

* Re: Program files environmental variables
  2021-11-23 13:10 ` Eliot Moss
@ 2021-11-23 15:15   ` john doe
  2021-11-23 15:27     ` Eliot Moss
  0 siblings, 1 reply; 8+ messages in thread
From: john doe @ 2021-11-23 15:15 UTC (permalink / raw)
  To: cygwin

On 11/23/2021 2:10 PM, Eliot Moss wrote:
> On 11/23/2021 4:02 AM, john doe via Cygwin wrote:
>  > Cygwins,
>  >
>  > Is there a way to get the value of PROGRAMFILES(x86) and PROGRAMW6432 in
>  > Bash:
>  >
>  > $ echo $PROGRAMFILES; echo "$PROGRAMFILES(x86)"; echo $PROGGRAMW6432
>  > C:\Program Files
>  > C:\Program Files(x86)
>  >
>  > $ cmd.exe /C "echo %PROGRAMFILES% %PROGRAMFILES(x86)% %PROGRAMW6432%"
>  > C:\Program Files C:\Program Files (x86) C:\Program Files
>  >
>  >
>  > PROGRAMFILES works in Bash but not the other two.
>
> PROGRAMW6432 exists in my Cygwin bash, and I know I did not set it

What version of Cygwin bash are you using?

> explicitly.  As for the x86 one, parentheses are not allowed in
> bash variable names.  In principle one could set up, say,
> PROGRAMFILESx86, however no path of that kind is around in my
> bash.  It would be possible to read it out and setup the variable.
> I found, for example, that this prints out the setting of the
> variable (but with other gorp you'd have to edit out):
>
> echo "echo %PROGRAMFILES(x86)%; exit" | cmd
>

Thank you.

--
John Doe

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

* Re: Program files environmental variables
  2021-11-23 15:15   ` john doe
@ 2021-11-23 15:27     ` Eliot Moss
  0 siblings, 0 replies; 8+ messages in thread
From: Eliot Moss @ 2021-11-23 15:27 UTC (permalink / raw)
  To: john doe, cygwin

On 11/23/2021 10:15 AM, john doe via Cygwin wrote:
> On 11/23/2021 2:10 PM, Eliot Moss wrote:
>> On 11/23/2021 4:02 AM, john doe via Cygwin wrote:
>>  > Cygwins,
>>  >
>>  > Is there a way to get the value of PROGRAMFILES(x86) and PROGRAMW6432 in
>>  > Bash:
>>  >
>>  > $ echo $PROGRAMFILES; echo "$PROGRAMFILES(x86)"; echo $PROGGRAMW6432
>>  > C:\Program Files
>>  > C:\Program Files(x86)
>>  >
>>  > $ cmd.exe /C "echo %PROGRAMFILES% %PROGRAMFILES(x86)% %PROGRAMW6432%"
>>  > C:\Program Files C:\Program Files (x86) C:\Program Files
>>  >
>>  >
>>  > PROGRAMFILES works in Bash but not the other two.
>>
>> PROGRAMW6432 exists in my Cygwin bash, and I know I did not set it
> 
> What version of Cygwin bash are you using?

4.4.12(3)

Yes, printenv is a much more elegant solution than mine!

Cheers - EM

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

* Re: Program files environmental variables
  2021-11-23  9:02 Program files environmental variables john doe
                   ` (2 preceding siblings ...)
       [not found] ` <DB9PR08MB6842C067DA1DB291FBD666A0E9609@DB9PR08MB6842.eurprd08.prod.outlook.com>
@ 2021-11-23 18:07 ` Brian Inglis
  3 siblings, 0 replies; 8+ messages in thread
From: Brian Inglis @ 2021-11-23 18:07 UTC (permalink / raw)
  To: cygwin

On 2021-11-23 02:02, john doe via Cygwin wrote:
> Cygwins,
> 
> Is there a way to get the value of PROGRAMFILES(x86) and PROGRAMW6432 in
> Bash:
> 
> $ echo $PROGRAMFILES; echo "$PROGRAMFILES(x86)"; echo $PROGGRAMW6432
> C:\Program Files
> C:\Program Files(x86)
> 
> $ cmd.exe /C "echo %PROGRAMFILES% %PROGRAMFILES(x86)% %PROGRAMW6432%"
> C:\Program Files C:\Program Files (x86) C:\Program Files
> 
> 
> PROGRAMFILES works in Bash but not the other two.
> 
> I could not find anything relevent in the archive or when googling.

On my system under only the following Program... variables are exposed:

$ echo $ProgramData $PROGRAMFILES $ProgramW6432	# x64
C:\ProgramData C:\Program Files C:\Program Files
$ echo $ProgramData $PROGRAMFILES $ProgramW6432	# x86
C:\ProgramData C:\Program Files (x86) C:\Program Files

It is often a better idea to use cygpath options or Windows folder ids:

"System information:
-A, --allusers        use `All Users' instead of current user for -D, -P
-D, --desktop         `Desktop' directory
-H, --homeroot        `Profiles' directory (home root)
-O, --mydocs          `My Documents' directory
-P, --smprograms      Start Menu `Programs' directory
-S, --sysdir          system directory
-W, --windir          `Windows' directory
-F, --folder ID       special folder with numeric ID"

$ for f in {0..64}; do
     p=`cygpath -UF $f 2> /dev/null` && [ -n "$p" ] && echo $f $p
   done # sanitized
  0 $HOME/Desktop
  2 $HOME/AppData/Roaming/Microsoft/Windows/Start Menu/Programs
  5 $HOME/Documents
  6 $HOME/Favorites
  7 $HOME/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup
  8 $HOME/AppData/Roaming/Microsoft/Windows/Recent
  9 $HOME/AppData/Roaming/Microsoft/Windows/SendTo
11 $HOME/AppData/Roaming/Microsoft/Windows/Start Menu
13 $HOME/Music
14 $HOME/Videos
16 $HOME/Desktop
19 $HOME/AppData/Roaming/Microsoft/Windows/Network Shortcuts
20 /proc/cygdrive/c/Windows/Fonts
21 $HOME/AppData/Roaming/Microsoft/Windows/Templates
22 /proc/cygdrive/c/ProgramData/Microsoft/Windows/Start Menu
23 /proc/cygdrive/c/ProgramData/Microsoft/Windows/Start Menu/Programs
24 /proc/cygdrive/c/ProgramData/Microsoft/Windows/Start 
Menu/Programs/StartUp
25 /home/Public/Desktop
26 $HOME/AppData/Roaming
27 $HOME/AppData/Roaming/Microsoft/Windows/Printer Shortcuts
28 $HOME/AppData/Local
29 $HOME/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup
30 /proc/cygdrive/c/ProgramData/Microsoft/Windows/Start 
Menu/Programs/StartUp
31 $HOME/Favorites
32 $HOME/AppData/Local/Microsoft/Windows/INetCache
33 $HOME/AppData/Local/Microsoft/Windows/INetCookies
34 $HOME/AppData/Local/Microsoft/Windows/History
35 /proc/cygdrive/c/ProgramData
36 /proc/cygdrive/c/Windows
37 /proc/cygdrive/c/Windows/System32
38 /proc/cygdrive/c/Program Files
39 $HOME/Pictures
40 $HOME
41 /proc/cygdrive/c/Windows/SysWOW64
42 /proc/cygdrive/c/Program Files (x86)
43 /proc/cygdrive/c/Program Files/Common Files
44 /proc/cygdrive/c/Program Files (x86)/Common Files
45 /proc/cygdrive/c/ProgramData/Microsoft/Windows/Templates
46 /home/Public/Documents
47 /proc/cygdrive/c/ProgramData/Microsoft/Windows/Start 
Menu/Programs/Administrative Tools
48 $HOME/AppData/Roaming/Microsoft/Windows/Start 
Menu/Programs/Administrative Tools
53 /home/Public/Music
54 /home/Public/Pictures
55 /home/Public/Videos
56 /proc/cygdrive/c/Windows/Resources
59 $HOME/AppData/Local/Microsoft/Windows/Burn/Burn

These output nothing:

$ printenv 'Program Files (x86)'
$ printenv 'ProgramFiles(x86)'

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

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
[Data in binary units and prefixes, physical quantities in SI.]

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

end of thread, other threads:[~2021-11-23 18:07 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-23  9:02 Program files environmental variables john doe
2021-11-23  9:52 ` Csaba Raduly
2021-11-23 10:40   ` Lemures Lemniscati
2021-11-23 13:10 ` Eliot Moss
2021-11-23 15:15   ` john doe
2021-11-23 15:27     ` Eliot Moss
     [not found] ` <DB9PR08MB6842C067DA1DB291FBD666A0E9609@DB9PR08MB6842.eurprd08.prod.outlook.com>
2021-11-23 15:11   ` john doe
2021-11-23 18:07 ` Brian Inglis

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).