Skip to content

Instantly share code, notes, and snippets.

@imasimali
Created November 17, 2021 18:16
Show Gist options
  • Save imasimali/f54e5a5ffb7503528ffda3efea92e637 to your computer and use it in GitHub Desktop.
Save imasimali/f54e5a5ffb7503528ffda3efea92e637 to your computer and use it in GitHub Desktop.
Run your C program in gcc with one line.
Add aliases in your .(shell)rc:
alias gcb='f(){ gcc "$1" -o "$2"; ./"$2"; unset -f f; }; f'
alias gcr='f(){ gcc "$1"; ./a.out; rm -f a.out; unset -f f; }; f'
The first modifies the name of the binary and executes it. The second compiles, runs, and delete the binary.
Demo gcb:
~$ gcb main.c build
Hello World
~$ ls
main.c build
Demo gcr:
~$ gcr main.c
Hello World
~$ ls
main.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment