DOS Command :SET

JITJIT Member Posts: 32 ■■□□□□□□□□
I have downloaded Java SDK and placed in C directory. However to access any executable file in SDK, as directed by Sun, I have put SET PATH = %PATH%;C:\j2sdk1.4.2; in autoexec.bat file

I understand the meaning and implication of SET/PATH environement variable. But could some of you please explain what do you mean by SET PATH=%PATH%?

I would really appreciate your help in this regard!

Comments

  • lazyartlazyart Member Posts: 483
    %PATH% is replaced by the PATH value that is already there when the statement is executed. This allows you to quickly add something to the PATH setting without having to type it in each time.

    ex:

    SET PATH=C:\;C:\WINDOWS;C:\WINDOWS\COMMAND
    SET PATH=C:\WINDOWS\SYSTEM;%PATH%

    After both are executed, PATH will be
    C:\WINDOWS\SYSTEM;C:\;C:\WINDOWS;C:\WINDOWS\COMMAND
    I'm not a complete idiot... some parts are missing.
  • JITJIT Member Posts: 32 ■■□□□□□□□□
    Thanks Lazyart for your feedback. I have understood that % PATH% in second line has been replaced by the SET PATH of first line. But tell me one thing if I do not put %PATH% in second line, what will happen? I feel that without %PATH% also, the results will be same. Could you please claify me?

    Thanks in advance!
  • lazyartlazyart Member Posts: 483
    If you don't put it in the second line, your path will become C:\j2sdk1.4.2;

    Any program that relied on the other items in your PATH variable won't find they are looking for.

    For an exercise, go to a command prompt and type PATH.. it will display the current path. Change it and type PATH again to see the effect. Reboot to reset the value to what it should be.
    I'm not a complete idiot... some parts are missing.
  • JITJIT Member Posts: 32 ■■□□□□□□□□
    I appreciate your spending time in clarifying my doubt.

    I have understood something, but not fully. Let me go through a DOS book and I will come back to you again.
  • WebmasterWebmaster Admin Posts: 10,292 Admin
    If you need more info about the use of system variables try accessing help from Environment Variables which you can access by clicking the Environment Variables button on the Advanced tab of the System Properties.
  • JITJIT Member Posts: 32 ■■□□□□□□□□
    Hello Johan, I am using WIN 98SE not WIN 2000. However, I can see all environment variables by typing set command. In my autoexec.bat I have deleted %path%, and still path to c:\j2sdk is working. My question is that why should I put %path% before c:\j2sdk? Lazyart has explained something. I have to figure out the rest.

    Once again thank you for spending your time!
  • WebmasterWebmaster Admin Posts: 10,292 Admin
    I think Lazyart has explained it rather well, but I'll try a different approach:

    Forget about PATH for a second.

    the set command can be used to set environment variables to which developers and users can refer in scripts, software and such. For example, you can set X to be 1 using the set x=1 command. You can also set x to be multiple values, for example 1 and 2, using the command set x=1;2 using the ; as a separator. If instead you would have used x=2 the contents of the variable (1) would be replaced with 2. Imagine you have set x to be 1;2;3;4;5;6;7;8;9;10;11;12;13;14;15 and you want to add 16, you wouldn't want to type set x=1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16 but instead you would say that x is the current contents of x and 16 using the command set=%x%;16

    Back to the PATH, instead of typing all the paths that are currently in the PATH variable and append it with the new one you want, you would set path to be the current path (represented by %path%) + the new path (;c:\j2sdk) set path=%path%;c:\j2sdk

    BUT, by now I think I know why this gave you a hard time to understand... because you don't need to do this at all.
    If this needs to be configured in your autoexec.bat, you wouldn't use the %path% variable you would just add ;c:\j2sdk to the current path statement. Setting the path using the set command in the command console is just temporarily, untill the computer is restarted. And since you probably want c:\j2sdk to be in your path whenever your computer starts, the use of %path% is not appropriate... like I said, just extend the current set path statement in the autoexec.bat

    Johan
  • JITJIT Member Posts: 32 ■■□□□□□□□□
    Hello Johan, you have correctly understood my confusion. In autoexec.bat file, I don't see any path variable. However, when I write path command, I see c:\windows; c:\windows\command. I feel these are default settings and have been set in invisible IO.SYS file(I know that IO.SYS has replaced many contents of autoexec.bat). That is the reason I have to put %path% before c:\jdk.... So that if I write directly path c:\jdk.., it will replace earlier settings c:\windows; c:\windows\command etc.

    Am I correct?
  • JITJIT Member Posts: 32 ■■□□□□□□□□
    Johan, you are great!!!
  • lazyartlazyart Member Posts: 483
    your are right-- without %path% you will replace the current value.

    With %path% it will include the then current path with whatever you are adding to it.

    You can also optimize the PATH statement-- The OS will search the directories in the order they are listed. Put the most often used directories first.

    The reason why JDK works with or without %PATH% is because you explicitly put it in the final SET PATH command.

    If you add a PATH statement later in your autoexec.bat (or even at the prompt) and fail to include %PATH%, the OS will not look in the JDK directory and you will not be able to use java (unless of course you are already in the JDK directory).
    I'm not a complete idiot... some parts are missing.
Sign In or Register to comment.