4 ms·
I just tried it out. I wrote this bash script: #!/usr/bin/env bash start_time=$(gdate +%s%3N) # Function to handle Ctrl+C (SIGINT) on_ctrl_c()
by shawabawa3 2y ago
I just tried it out.
I wrote this bash script:
#!/usr/bin/env bash
start_time=$(gdate +%s%3N)
# Function to handle Ctrl+C (SIGINT)
on_ctrl_c() {
end_time=$(gdate +%s%3N)
total_ms=$((end_time - start_time))
# Calculate integer seconds and the remaining milliseconds
seconds=$((total_ms / 1000))
millis=$((total_ms % 1000))
# Print the runtime in seconds.milliseconds
echo "Script ran for ${seconds}.$(printf '%03d' ${millis}) seconds."
exit 0
}
# Trap Ctrl+C (SIGINT) and call on_ctrl_c
trap on_ctrl_c INT
# Keep the script running indefinitely
while true; do
sleep 1
done
And then i typed "bash sleep.sh git push origin master<enter><ctrl+C>"
and got "Script ran for 0.064 seconds."