Is there any way to create a command on Command Prompt like I want to create a command named createdirectory(I know there is an existing command for that but take this as an example) . when i execute the command "createdirectory" it will run a python file. I want it in such a way that i can run this command from anywhere any disk volume or any folder.
If you know anything then please post your answer.
Thanks!
Shell commands are basically either aliases or programs stored on disk. You can write your programs put them in some directory and add that directory path to the shell's PATH
variable.
Let's say you have a program called create.py
which creates the directories. You can follow these two ways to make them available as command on a shell
Assume create.py
is present in /home/bob/scripts
directory
Create a file called createDirectory
with below content in /home/bob/scripts
python /home/bob/scripts/create.py $*
Add /home/bob/scripts
to the PATH
export PATH="$PATH:/home/bob/scripts"
alias createDirectory="python /home/bob/scripts/create.py"
createDirectory <whatever> <arguments> <your> <program> <expects>
NOTE : You can add this alias command and export command to ~/.bashrc file so that it is run when you start a shell
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.