Skip to content

Instantly share code, notes, and snippets.

@ianmuchina
Last active July 7, 2021 06:00
Show Gist options
  • Select an option

  • Save ianmuchina/02816957dc6212d32c96f684626eb4e9 to your computer and use it in GitHub Desktop.

Select an option

Save ianmuchina/02816957dc6212d32c96f684626eb4e9 to your computer and use it in GitHub Desktop.
Compile and run c program in one command. similar to go run
#!/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