Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the board
Thread view  Mix view  Order
CluelessInSeattl(R)

Seattle, USA,
07.01.2013, 17:19
 

How 2 add directory to PATH from command line (Users)

EDIT: Never mind! After first posting this I think I just remembered the name of that command: APPEND! But now, I don't know how to delete my post. Is there a way to do that?
----------------------------------------------------------------------------

As some of you who follow this forum already know, I'm an MS-DOS old-timer who is trying to revive my old MS-DOS 6.21 system after a hiatus of a decade or more. My memory is failing me these days, and due to chronic illness, I suffer from worsening cognitive deficits, so my DOS skills are pretty rusty.

Today I'm trying to figure out a shortcut for adding a directory to an already lengthy PATH statement.

I'd like to do it from the command line, but without the hassle of having to retype the entire PATH statement for the SET command. My eyesight is poor, as is my coordination, so typing an error-free PATH statement is a challenge to me.

Is there a command in MS-DOS 6.21 that I can use to temporarily "insert" or "add-on" a directory to the existing PATH statement?

The reason I want to do this is to try out a program. So I don't want to update the path statement in my AUTOEXEC.BAT file until I decide whether or not I'll continue to use this new program.

---
Will in Seattle
a.k.a. "Clueless"
Running MS-DOS 6.21

Arjay(R)

07.01.2013, 18:05

@ CluelessInSeattl

How 2 add directory to PATH from command line

> Is there a command in MS-DOS 6.21 that I can use to temporarily "insert" or
> "add-on" a directory to the existing PATH statement?

I am not near a PC, so from memory:
set oldpath=%path%
path=%path%;c:\testdir1;c:\testdir2
[do testing]
path=%oldpath%
set oldpath=

First line will backup the path to a temporary environment variable (providing you have room in the environment, if not you can always expand it). Second line adds 2 new directories onto the end of the path. Do testing line speaks for itself, 3rd line restores original path and 4th line removes temporary oldpath variable. Depenfing on what your doing not all the lunes ate required and a quick trick is to start a new command.com session, change the path then just do an exit when done.

Most of my batch files were designed to not require external programs if I could help it hence until you mentioned append I'd completely forgotten about it. A simple way of checking if the environment is big enough to backup another copy of the path is to do an if check like this:
if NOT "%path%"=="%oldpath%" goto PATHERROR

Re your autoexec.bat question I used to make mine runable again by doing a simple check if it had already run, e.g
if NOT "%booted%"=="" GOTO rerun
:firstrun
set booted=1
rem do 1st boot stuff e.g load keybd tsr
goto end

:rerun
set path=c:\dos;c:\bcc
goto end

:end
> The reason I want to do this is to try out a program. So I don't want to
> update the path statement in my AUTOEXEC.BAT file until I decide whether or
> not I'll continue to use this new program.

marcov(R)

07.01.2013, 18:22

@ Arjay

How 2 add directory to PATH from command line

That's code similar to what I use, I use the following code (cmd.exe though, don't know how portable NEQ is to Dos) to switch between multiple versions of toolchains.

if "%OLDPATH%" neq "" goto :nosave
set OLDPATH=%PATH%
:nosave
SET PATH=%OLDPATH%
PATH d:\pp26\bin\i386-win32;%PATH%

the main reason is that the various compilers/ides (BP,Delphi, cygwin and fpc verions) all bring at least their own "make", and some of them also have own copies of other binaries(as,ld etc).

This makes it always possible to "undo" changes to the path by setting PATH to OLDPATH.

P.s. I know that the last two lines can be combined, but my old generator doesn't do it

Arjay(R)

07.01.2013, 22:07

@ marcov

How 2 add directory to PATH from command line

> That's code similar to what I use, I use the following code (cmd.exe
> though, don't know how portable NEQ is to Dos)
NEQ is not portable as came about later, this version should be in case you ever need it for info:

if NOT "%oldpath%" == "" goto nosave
:nosave
set path=%oldpath%
path d:\pp26\bin\i386-win32;%path%

disclaimer: typed from memory not on a pc after a few beers. ;)

> the main reason is that the various compilers/ides (BP,Delphi, cygwin and fpc
I know the problem well !

> P.s. I know that the last two lines can be combined, but my old generator
> doesn't do it
number of times I've seen ampersand break shells.... amusingly I have just remembered the reverse problem adding back characters that some DOS utils used to block unnecessarily, e.g. () in volume labels. I have just remembered one of my first DOS utils (never widely shared as predated my involvement with BBS's) which patched label to allow 4-5 characters to be used.

Rugxulo(R)

Homepage

Usono,
07.01.2013, 22:33

@ CluelessInSeattl

How 2 add directory to PATH from command line

> EDIT: Never mind! After first posting this I think I just remembered the
> name of that command: APPEND! But now, I don't know how to delete my
> post. Is there a way to do that?
> ----------------------------------------------------------------------------
>
> Today I'm trying to figure out a shortcut for adding a directory to an
> already lengthy PATH statement.

No, I don't think APPEND is what you want. Also keep in mind that a PATH can only be approx. 128 bytes long, at least in most common environments (like your MS-DOS 6.21).

From cmdline, you can change the PATH easily, as mentioned, but most shells, including MS-DOS 6.21's, don't always expand env. vars when setting other environment variables. So "path c:\temp;%PATH%" doesn't work in MS-DOS 6.x (but works in 7.x's COMMAND.COM, IIRC). The workaround is to use a .BAT, since it always works inside there.

In my case, since I sometimes muck with the PATH and want to revert to a known stable state, I keep a file called MYPATH.BAT which switches back to the standard setup. In fact, I even call it from within AUTOEXEC.BAT:

REM N.B. this way avoids hardcoding the filename twice

for %%a in (c:\utils\mypath.bat) do if exist %%a call %%a


And here's MYPATH.BAT:


@echo off
REM mypath.bat
path c:\;c:\fdos\bin;c:\hx\bin;c:\utils
if not "%1"=="" path %PATH%;%1

marcov(R)

09.01.2013, 16:55

@ Rugxulo

How 2 add directory to PATH from command line

> No, I don't think
> APPEND is what
> you want. Also keep in mind that a PATH can only be approx. 128 bytes long,
> at least in most common environments (like your MS-DOS 6.21).

(couldn't 4dos do 255 char environment vars? Might point to the limitation being in the shell)

Back to the board
Thread view  Mix view  Order
15108 Postings in 1358 Threads, 246 registered users, 10 users online (0 registered, 10 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum