Hugo Woesthuis
Hugo Woesthuis

Reputation: 193

How to implement your own command prefix in a shell?

I've noticed that if you wanted to use, let's say .NET Core, you can call it from any directory by using dotnet and then your arguments after that.

Now let's say I need to run my own console application from any directory possible to encrypt files, I would like to call CryptApp --encrypt --foo, which results into my program encrypting that file.

Normally to run my program, which is a .NET Core console app, I need to do the following: dotnet CryptApp.dll -- --encrypt --foo. How can I convert that into CryptApp --encrypt --foo?

Note that I am not taking about a specific terminal here, because I want to know how to do this for mainly CMD (Windows) and the terminal in linux/macOS systems.

Also, I don't really know how to format this question title properly, so if there is someone that can get a better title, please go ahead and edit the title.

Upvotes: 0

Views: 74

Answers (1)

lit
lit

Reputation: 16246

Create a file in a directory in you PATH variable named CryptApp.bat. Set the contents of CryptApp.bat to:

dotnet CryptApp.dll -- %~1 %~2

After the CryptApp.bat file exists in a directory in your PATH, you can use the command:

CryptApp --encrypt --foo

The contents of a CryptApp file on Linux depends on how the command is made available on the platform.

Upvotes: 1

Related Questions