Ubuntu – Aliases – able to pass arguments

aliasbashcommand line

I want to make an alias in my .bashrc or .bashrc_aliases file (probably the latter).
Specifically, I want to call the clang command for my *.c file I'm writing. What I'm looking for is best summed up if I provide an example:

I have program1.c written
I want to be able to type (in the terminal) compile program1, and something like the following should be actually run:

clang -ggdb -std=c99 -Wall -Werror   program1.c -lcrypt -lcs50 -lm -o program1

For those who have taken Harvard's CS50 class, you will recognize this as their make command. So if the above is impossible, and you know another way to make this happen, I'm all ears. I'm trying to avoid using their VM, as my netbook isn't really up to par to handle a VM.

Best Answer

No, you can't pass arguments to an alias. But you can define a function:

compile() { 
  clang -ggdb -std=c99 -Wall -Werror ${1}.c -lcrypt -lcs50 -lm -o $1 ;

(you can put it all in one line if you wish, just mind the semicolon at the end of the command)

This will work as intended and is the recommended idiom that should replace aliases for all but trivial purposes.

But maybe what you really need is a Makefile?