Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent source command in Windows CMD as in bash or tcsh?

I know that in the unix world, if you edit your .profile or .cshrc file, you can do a source ~/.profile or source ~/.cshrc to get the effect on your current session. If I changed something in the system variable on Windows, how can I have it effect the current command prompt session without exiting the command prompt session and opening another command prompt session?

like image 878
mart2001 Avatar asked May 01 '12 18:05

mart2001


People also ask

What is Windows equivalent of source command?

The winget tool source command allows you to manage sources for Windows Package Manager. With the source command, you can add, list, update, remove, reset, or export repositories.

Does Windows CMD use Bash?

To access the shell, simply type 'bash' in the Windows command prompt, and everything is good to go.

Is CMD same as Bash?

CMD is the command line for Microsoft Windows operating system, with command-based features. Powershell is a task-based command-line interface, specifically designed for system admins and is based on the . Net Framework. Bash is a command-line and scripting language for most Unix/Linux-based operating systems.

How do you source a file in Windows?

If you select and hold (right-click) a file or folder in this dialog box, a standard Windows shortcut menu appears. Select OK to append the selected folder to the source path and return to the Source Search Path dialog box.


3 Answers

In the usual Windows command prompt (i.e. cmd.exe), just using call mybat.bat did what I wanted. I got all the environment variables it had set.

like image 98
Eike Avatar answered Oct 07 '22 11:10

Eike


The dos shell will support .bat files containing just assignments to variables that, when executed, will create the variables in the current environment.

  c:> type EnvSetTest.bat
  set TESTXYZ=XYZ

  c:> .\EnvSetTest.bat

  c:> set | find "TESTX"
  TESTXYZ=XYZ
  c:>

IHTH.

like image 29
shellter Avatar answered Oct 07 '22 11:10

shellter


Following example will help you to solve your problem.

env.bat This file is for setting variables. Its contents are given blow.

set name="test3"

test.bat Our main batch file.

call env.bat
call print.bat
pause

Now print.bat batch file to print variables. Its contents given below

echo %name%
like image 9
Fathah Rehman P Avatar answered Oct 07 '22 09:10

Fathah Rehman P