Last active
July 7, 2021 06:00
-
-
Save ianmuchina/02816957dc6212d32c96f684626eb4e9 to your computer and use it in GitHub Desktop.
Compile and run c program in one command. similar to go run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Usage cr <filename> <args> | |
| # Filename without extension | |
| file=${1%.*} | |
| # Error checks | |
| # If no commands are given | |
| if [ $# -eq 0 ]; then | |
| echo "Script to compile and run c code in one command\nUsage: cr file <args>" | |
| exit 1 | |
| fi | |
| # Exit if file does not exist | |
| if [ ! -f ${file}.c ]; then | |
| echo "${file}.c does not exist." | |
| exit 1 | |
| fi | |
| cc ${file}.c -o $file && ./${file} ${@:2} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment