Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

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?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.