Operating System - OpenVMS
1752866 Members
4253 Online
108791 Solutions
New Discussion юеВ

newpie question: reassign a symbol

 
YE LIU_1
Frequent Advisor

newpie question: reassign a symbol

Dear VMS users,

I have a newpie question: how to reassign/overwrite global symbol definition. For example, I have a script like:

$! reassign cmd_dir and cfg_dir
$ cmd_dir == "DEV_SRC2:[YLIU.BUILD.ESX.COM]"
$ cfg_dir == "DEV_SRC2:[YLIU.BUILD.ESX.CFG]"

After I execute this script, I notice that cmd_dir and cfg_dir still show the old value as if my assignments didn't happen.

Can you give me some pointers?

YE LIU
5 REPLIES 5
labadie_1
Honored Contributor

Re: newpie question: reassign a symbol

Hello Ye

A symbol can be local
cmd := $ sys$login:myprog.exe

or global
cmd :== $ sys$login:myprog.exe

How is your symbol cmg_dir defined before the procedure and inside your procedure ?
Can you post the result of

$ sh symb /local cmd_dir
$ sh symb/glob cmg_dir
Jon Pinkley
Honored Contributor

Re: newpie question: reassign a symbol

YE LIU,

Two things to be aware of:

1. All symbols are process specific, i.e. a symbol created in one process isn't visible by DCL in another process. It may appear that symbols are visible to subprocesses, but that is only because by default, symbols are copied to the new subprocess process when the SPAWN command is used.

2. Every "level" of DCL (as shown by f$environment("depth") has its own local symbols. @ or call in a command procedure creates a new level. What DCL sees is the highest level local symbol that matches, and if no local symbols exist, then the global symbol that matches will be used.

Can you show the output of

$ show symbol cmd_dir

Before you execute the command procedure (script)?

If the value is separated from the symbol name by a single equal sign " = ", then it is a local symbol, and it has a higher precedence than a global symbol with the name name.

Here's an example:

$ sho symbol top
TOP == "MONITOR PROC/TOPCPU"
$ top="monitor process/topcpu" ! local symbol
$ sho sym top
TOP = "monitor process/topcpu"
$ ! using Brian Schenkenberger's SYMBOL program so we can see all instances of the "TOP" symbol
$ symbol/show top
[-] TOP == "MONITOR PROC/TOPCPU"
[0] TOP = "monitor process/topcpu"
$ top=="Monitor Proc/TOPCPU" ! redefinition of global symbol
$ sho sym top
TOP = "monitor process/topcpu"
$ symbol/show top
[-] TOP == "Monitor Proc/TOPCPU"
[0] TOP = "monitor process/topcpu"
$

Jon
it depends
Jess Goodman
Esteemed Contributor

Re: newpie question: reassign a symbol

Local symbols take precedence over global symbols, so you can redefine a global symbol any number of times, but if it was already defined as a local symbol then the local symbol definition is what is visible.

A common DCL mistake is to use a == global symbol assignment when a = local symbol assignment will do.

You should use local symbols as variables in a DCL .COMmand procedure. They will even be passed INTO a nested @procedure call.

Generally you only need to use global symbols for two cases:
* When you want to RETURN a value from a nested @procedure to the calling procedure.
* When defining a command macro symbol in your LOGIN.COM or a similar procedure that you will be using at the interactive DCL prompt.

(When defining command macro symbols in a procedure for use in that procedure a local symbol will do.)
I have one, but it's personal.
Hoff
Honored Contributor

Re: newpie question: reassign a symbol

Ignoring the discussion of DCL symbols and the scope of such symbols, the use of logical names would probably be more typical here.

Something akin to the following (untested) DCL code might be used here:

$ dev = f$parse("DEV_SRC2",,,"DEVICE"-
"NO_CONCEAL")
$ DEFINE/TRAN=(CONC,TERM)/NOLOG -
YLIU_BUILD_ROOT -
'dev'[YLIU.BUILD.ESX.]
$ DIRECTORY YLIU_BUILD_ROOT:[COM]
$ DIRECTORY YLIU_BUILD_ROOT:[CFG]

This gets the device name behind the DEV_SRC2 logical name, and sets up your own concealed terminal rooted logical name -- basically a construct that looks like a device, but that incorporates (and hides) a directory -- and then issues a couple of DIRECTORY commands to demonstrate the use of the logical name.

Depending on exactly how the existing DEV_SRC2 logical name is defined, a tweak or two to the DCL might be needed.

YE LIU_1
Frequent Advisor

Re: newpie question: reassign a symbol

Thanks all for the informative reply. I resolved the problem.

YE LIU