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 33 times
0
-
2See Aliases - able to pass arguments? – steeldriver Mar 05 '24 at 17:18
-
3Does this answer your question? Can I pass arguments to an alias command? – mchid Mar 05 '24 at 17:35
-
2Maybe a Makefile might be a better way to achieve this? – moo Mar 05 '24 at 17:40
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
- 43,546
- 8
- 97
- 150