0

I was wondering if there's any way to create an alias for a list of arguments.

Considering the following commands:

my_command --class_a_argument_one --class_a_argument_two --class_a_argument_three --class_a_argument_four

my_command --class_b_argument_one --class_b_argument_two --class_b_argument_three --class_b_argument_four

my_second_command --class_a_argument_one --class_a_argument_two --class_a_argument_three --class_a_argument_four

I want to create two different aliases for each list of arguments so that I could run these two commands using these:

my_command class_a_arguments
my_second_command class_a_arguments
my_command class_b_arguments

Any ideas?

2 Answers 2

3

Put your arguments in an array, and then invoke the command using that array.

$ arr1=(-e '\e[32mHello world\e[0m')
$ echo "${arr1[@]}"
Hello world
Sign up to request clarification or add additional context in comments.

Comments

2

They're called variables.

A="foo bar"
B="baz qoox"
my_command $A
your_command $B

1 Comment

Yeah, I know. But he seems to be a shell newbie, so it's good for him to encounter that problem if need be.

Your Answer

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.