Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

    if [ "$(uname -s)" == "Linux” ]; then 
       stuff-goes-here
    else # Assume MacOS 
While probably true for most folks, that’s hardly what I’d call great for everybody not on Linux or a Mac.


Gotta draw a line somewhere


Yeah, but you could at least elif is mac then ... else unsupported end.


If you look at the next couple of lines of the code, it emits a warning if neither command is found, but carries on. Running without in this case works but it's not optimal, as described in the warning message.


The following check for gtimeout means that other OSs that don't have the expected behaviour in either command won't break the script, you'll just get a warning message that isn't terribly relevant to them (but more helpful than simply failing or silently running without timeout/gtimeout. Perhaps improving that message would be the better option.

Though for that snippet I would argue for testing for the command rather than the OS (unless Macs or some other common arrangement has something incompatible in the standard path with the same command name?).


The worst part is that if you're not running Linux but have a perfectly working 'timeout' command, the script will ignore it and fail.


Eh. It’s true for most, and if not, it’s probably still a *BSD, so there’s a good chance that anything written for a Mac will still work.

That said, I’ve never used any of the BSDs, so I may be way off here.





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: