Coming from a linux shell, I'm used to being able to source a file into the current environment. How can I do this in the Windows cmd
command prompt?
eg in linux I can create an alias for a long complicated command:
alias shortcut="some super long command with lots of --options and arguments etc"
alias another="some other super long command with lots of --options and arguments etc"
alias again="yet another super long command with lots of --options and arguments etc"
then I can save that to a file and just source aliases.bash
and even automatically load it when starting the shell such as when used in a .bashrc
or .bash_profile
file.
I know I can do something similar at runtime in the cmd
prompt with doskey
doskey shortcut="some super long command with lots of --options and arguments etc"
But how can I save all these doskey
entries into a master file that I can load into the current environment? Even better, how can I load them automatically when starting the cmd
prompt?
Answered here: https://stackoverflow.com/a/21040825/3173271
You load up your commands into a bat, and then get them run into the command processor at logon by creating an AUTORUN entry in the registry pointing to the batch file.
You can add an AutoRun entry to your registry to automatically run a .cmd file when cmd
starts.
Create a file C:\\Users\\Jeff\\autorun.cmd
and add your doskey commands to it like so:
@echo off
doskey shortcut="some super long command with lots of --options and arguments etc"
doskey another="some other super long command with lots of --options and arguments etc"
doskey again="yet another super long command with lots of --options and arguments etc"
Then, edit HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Command Processor
in your registry to contain something like:
AutoRun=C:\\Users\\Jeff\\autorun.cmd
Based on information provided from https://superuser.com/a/144348/201002 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.