Environment variables with user commands. I.e. ]cd %temp%

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !
Post Reply
User avatar
norbertjurkiewicz84
Posts: 62
Joined: Mon Nov 01, 2010 7:26 pm

Environment variables with user commands. I.e. ]cd %temp%

Post by norbertjurkiewicz84 »

Should something like this work?

⎕cmd 'echo %cas%'
C:\github\cas-6.0
]cd
C:\Users\norbet\Desktop
]cd %cas%
* Command Execution Failed: Unable to change directory
Vince|Dyalog
Posts: 439
Joined: Wed Oct 01, 2008 9:39 am

Re: Environment variables with user commands. I.e. ]cd %tem

Post by Vince|Dyalog »

Hi Norbert,

I have logged this as an RFE 18348.

Regards,

Vince
User avatar
Adam|Dyalog
Posts: 143
Joined: Thu Jun 25, 2015 1:13 pm

Re: Environment variables with user commands. I.e. ]cd %tem

Post by Adam|Dyalog »

In general, environment variable syntax is only recognised by shells and shell interfaces, not by applications, so this behaviour is consistent across all programs, by Dyalog and others.

The %name% syntax is specific to the Windows/DOS shells, while UX shells use $NAME, or ${NAME} if the name has unusual characters in it. SALT uses [name], but user commands in general don't support this. In any case, such a syntax might need a way to escape it if the literal characters are needed.

The formal way to achieve what you wrote is:
      ⎕SE.UCMD'CD ',⎕SE.Dyalog.Utils.Config'cas'

A couple of notes are in order:
  1. Changing directory while code is running can have unexpected consequences.
  2. It is considered bad practice to use user commands under program control.
Still, should you want to do this on a regular basis, you can roll your own user command pre-processor,
      '\[[^]]+]'⎕R{⎕SE.Dyalog.Utils.Config 1↓¯1↓⍵.Match}
which replaces text in square brackets with the corresponding environment variable.
Post Reply