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 !

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

Postby norbertjurkiewicz84 on Mon Jul 20, 2020 5:24 pm

Should something like this work?

⎕cmd 'echo %cas%'
]cd %cas%
* Command Execution Failed: Unable to change directory
User avatar
Posts: 60
Joined: Mon Nov 01, 2010 7:26 pm

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

Postby Vince|Dyalog on Tue Jul 21, 2020 1:16 pm

Hi Norbert,

I have logged this as an RFE 18348.


Posts: 334
Joined: Wed Oct 01, 2008 9:39 am

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

Postby Adam|Dyalog on Sun Jul 26, 2020 8:05 am

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.
User avatar
Posts: 84
Joined: Thu Jun 25, 2015 1:13 pm

Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest