2

How do I make an alias in my .bashrc such that I can run two commands with arguments?

For example, compile source and run.

gcc-run -lm example.c

would run

gcc -lm example.c
./a.out

The closest I found was this question but it doens't have any arguments.

1 Answer 1

5

If you want to pass an argument, you can't use an alias. You need to use a shell function. It sounds like you want something similar to

gcc-run () {
    gcc "$@"
    ./a.out
}    
Sign up to request clarification or add additional context in comments.

3 Comments

Another small related question. How would I then pick out individual arguments to use in an if-else statement?
the shell functions are simuliar as "normal" shell program, you can use $1 $2... for individual arguments.
You might actually want to make sure that compilation was successful. gcc-run () { gcc "$@" && ./a.out; }

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.