0

How can I alias a command that uses custom input in terminal?

For example, let's say a command

$ oj d https://codeforces.com/contest/1348/problem/A

In this command 1348 and 'A' can change. How can I achieve this?

Something like I can alias the whole command as,

$ oj d 1348 A

such that it can act like same.

asked May 4, 2020 at 9:18
1

1 Answer 1

2

Aliases do not accept parameters. You need to write a function or a separate script.

Bash/Zsh function:

Define the following function in your .bashrc/.zshrc depending on what interactive shell you use:

mycommand() {
 oj d https://codeforces.com/contest/"1ドル"/problem/"2ドル"
}

Shell script:

Create the file mycommand with the following content in your $PATH and make it executable:

#!/bin/sh
oj d https://codeforces.com/contest/"1ドル"/problem/"2ドル"

1ドル and 2ドル are positional parameters. If you call the script or function like $ mycommand 1348 A, 0ドル gets mapped to mycommand, 1ドル to 1348, 2ドル to A and so on. We put the double quotes around the variables in case they contain whitespace to prevent word splitting.

answered May 4, 2020 at 9:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.