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

This is not a best practices guide, please look forward to: https://mywiki.wooledge.org/BashGuide

For example, using cd "$(dirname "$0")" to get the scripts location is not reliable, you could use a more sophisticated option such as: $(dirname $BASH_SOURCE)



And THIS is the primary source of my furious hate in my toxic love-hate relationship with bash. Guy is writing bash FOR 10 FUCKING YEARS and still apparently doing it wrong in 10 letter oneliner.

When it comes to bash search for even simplest command/syntax always ALWAYS leads to stackoverflow thread with 50 answers where bash wizards pull oneliners from sleeves and nitpick and argue about various intricancies


It's a case of knowing the wooledge website (and working with shellcheck), or not. Picking snippets on stackoverflow will probably do more harm than good, tbh.


10 years of doing something wrong doesn't make it any better. 10 years of doing something and RTFM instead of random blog posts and SOF may help.


This is the way.

I'm more likely to use the BashFAQ though for actual snippets: https://mywiki.wooledge.org/BashFAQ

I start scripts from the very useful template at https://bash3boilerplate.sh/



Thank you to share. Can you provide an example where "$0" != "$BASH_SOURCE"?

Also, did you mean to write...?

    $(dirname "$BASH_SOURCE")"


Please read: https://mywiki.wooledge.org/BashFAQ/028 this will explain why it's not recommended to use $0


Thanks for sharing. The only actual useful thing I got from this post.




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

Search: