0

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.

1 Answers1

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