2

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

hymie
  • 1,982
  • 1
  • 13
  • 18
JDS
  • 16,388
  • 47
  • 161
  • 224
  • 1
    see http://stackoverflow.com/questions/13187987/tcsh-aliasing-find-directory-in-unix/13188466#13188466 . If you must have arugments, make shell scripts that are wrappers, essentially creating a function and alias to them. Good luck. – shellter Nov 06 '12 at 18:26

2 Answers2

3
alias whatever "cmd1; cmd2; cmd3"
Marc B
  • 356,200
  • 43
  • 426
  • 500
0

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"
macetw
  • 1,640
  • 1
  • 17
  • 26