112

I am trying to follow some instructions for creating a directory using the command line. The instructions are:

$ export PROJ_HOME=$HOME/proj/111
$ export PROJECT_BASEDIR=PROJ_HOME/exercises/ex1
$ mkdir -p $PROJ_HOME

Are these windows commands? Are there windows equivalents?

2

4 Answers 4

174

To translate your *nix style command script to windows/command batch style it would go like this:

SET PROJ_HOME=%USERPROFILE%/proj/111
SET PROJECT_BASEDIR=%PROJ_HOME%/exercises/ex1
mkdir "%PROJ_HOME%"

mkdir on windows doens't have a -p parameter : from the MKDIR /? help:

MKDIR creates any intermediate directories in the path, if needed.

which basically is what mkdir -p (or --parents for purists) on *nix does, as taken from the man guide

4
  • 2
    Doesn't seem to work on Windows10, I needed to do it manually.
    – Shadoweb
    Jan 17, 2016 at 17:43
  • 2
    Just verified on Windows10 and works for me @Shadowbob but maybe you have a space in one of the directory names?
    – rene
    Jan 17, 2016 at 19:21
  • 2
    will these environment variables be permanent using 'SET' in windows? I know that with export they will be temporary unless you add them to your ~/.bashrc
    – user137717
    Feb 5, 2016 at 18:31
  • 6
    @user137717 they are temporary. Use the setx command if you want to change/add those variable to the system or user settings and persist them.
    – rene
    Feb 5, 2016 at 18:49
5

There is not an equivalent statement for export in Windows Command Prompt. In Windows the environment is copied so when you exit from the session (from a called command prompt or from an executable that set a variable) the variable in Windows get lost. You can set it in user registry or in machine registry via setx but you won't see it if you not start a new command prompt.

5

you can use export if you have git-bash installed.

5
  • Its not working on windows. Jun 16, 2022 at 7:28
  • @AbhishekSachan are you using git bash? I crossed check it even now and its working for me. Jun 16, 2022 at 7:51
  • Somehow it's not working in windows 10. Might be some installation issue, thanks for confirming. Jun 17, 2022 at 14:36
  • Thanks, I forgot that this is an option. That's way easier than using the WSL.
    – Mat-KH
    Sep 6, 2022 at 12:52
  • it worked thanks... great help.... For people, its not working.. please try giving full path of the configuration file. Mar 7 at 13:49
4

Windows 10+, it is preserved for an user forever, run as admin for global var

setx myvariable myvariablevalue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.