Last active
August 25, 2022 12:33
-
-
Save rickwillcox/605685dd563dca96938a4d6b980ce411 to your computer and use it in GitHub Desktop.
A script that can watch a .c file for changes and if it detects a change it will recompile and run it again. Modified from a Stackoverflow answer.
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 | |
read -p 'Which c file to watch?: ' file_name | |
read -p 'Which gcc flags? Type them all with a space between: ' opt_flags | |
old_file_sig=$(stat -c %Z $file_name) | |
echo "Watching $file_name for changes..." | |
while true | |
do | |
new_file_sig=$(stat -c %Z $file_name) | |
if [[ "$new_file_sig" != "$old_file_sig" ]]; then | |
echo "" | |
echo "$file_name changed... compiling and running" | |
echo "" | |
gcc $file_name -O $opt_flags -o $file_name.o && ./$file_name.o | |
old_file_sig=$new_file_sig | |
echo "" | |
echo "Watching $file_name for changes..." | |
fi | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment