I'm trying to create custom alias to to compile and run my .c files in one command. I tried to add this line in /.bashrc_aliases alias runc='gcc $1 -lm && ./a.out' however I get an error and it seems like the .c file doesn't get passed to the gcc. Any help apreciated.
Asked
Active
Viewed 99 times
0
1 Answers
0
I don't think you can include a variable within an alias. And in any case, you cannot use a variable within single quotes, you'd have to use doublequotes instead.
This function should work. Place these lines in your .bashrc file or wherever you would put the alias.
runc () {
gcc "$1" -lm && ./a.out
}
And don't forget to source your .bashrc file after you have saved your edits.
. ~/.bashrc
mchid
- 44,904
- 8
- 102
- 162