Timeout a command in bash without unnecessary delay
问题 This answer to Command line command to auto-kill a command after a certain amount of time proposes a 1-line method to timeout a long-running command from the bash command line: ( /path/to/slow command with options ) & sleep 5 ; kill $! But it\'s possible that a given \"long-running\" command may finish earlier than the timeout. (Let\'s call it a \"typically-long-running-but-sometimes-fast\" command, or tlrbsf for fun.) So this nifty 1-liner approach has a couple of problems. First, the sleep