JDS
JDS

Reputation: 16978

C shell how to put multiple commands in an alias?

So C shell doesn't have functions I hear, and I need to use aliases... Let's say I have:

command1
command2
...
commandN

And in my mind these N commands make up a "function". Is there any way of putting them into 1 alias?

Also, if I need to pass any arguments to my "function" am I screwed?

Obligatory don't-blame-me-blame-my-company for using c shell.

Cheers

Upvotes: 2

Views: 8910

Answers (2)

macetw
macetw

Reputation: 1820

To have an alias do 2 things, simply add a semicolon, and ensure it is quoted.

alias func "echo do the thing ; echo do the other thing"

To use parameters with aliases, use the following notation.

alias funcargs "echo do the first thing \!:1 ; echo do the second thing \!:2"

Note, these are zero-indexed, with \!:0 being the name of the alias. Caution, if you don't supply an argument, you'd get a cryptic error message.

Here's the little thing I needed for this:

alias venv "python -m venv \!:1 ; source \!:1/bin/activate.csh"

Upvotes: 0

Marc B
Marc B

Reputation: 360612

alias whatever "cmd1; cmd2; cmd3"

Upvotes: 3

Related Questions