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

Hello fellow traveler. I've got 20 years of scripts with `if test` in them. I only use `[[` when I need functionality it provides that `test` does not (pattern or regex matching, typically, and for pattern matching I'll generally use a case statement instead).


Yeah that's when I use it too. I figure if I've already given into the temptations of Bash, I may as well go all the way. Sometimes if I'm feeling extra frisky I even do [[ .. ]] || { echo "error!" ; exit 1 }


I imagine most people have sets of macros they habitually add to any sufficiently complex script they're modifying...

  yelp(){
    es=$1
    shift
    echo "$@" >&2
    exit $es
  }
  
  test -d /tmp/goober || yelp 33 "couldn't find goober!"
(yes, I'm sure there are standards for exit status ranges and 33 is not such a thing)




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

Search: