3 ms·
This is not a best practices guide, please look forward to: https://mywiki.wooledge.org/BashGuide https://mywiki.wooledge.org/BashGuide For example, using cd "
by lockedinspace 4y ago
This is not a best practices guide, please look forward to: https://mywiki.wooledge.org/BashGuide 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)
- ndsipa_pomu 4y agoThis is the way. I'm more likely to use the BashFAQ though for actual snippets: https://mywiki.wooledge.org/BashFAQ https://mywiki.wooledge.org/BashFAQ I start scripts from the very useful template at https://bash3boilerplate.sh/ https://bash3boilerplate.sh/
- fomine3 4y agoAlso this http://wiki.bash-hackers.org/start http://wiki.bash-hackers.org/start
- pxtail 4y agoAnd 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
- marklgr 4y agoIt'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.
- myuzio 4y ago10 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.
- throwaway2037 4y agoThank you to share. Can you provide an example where "$0" != "$BASH_SOURCE"? Also, did you mean to write...? $(dirname "$BASH_SOURCE")"
- lockedinspace 4y agoPlease read: https://mywiki.wooledge.org/BashFAQ/028 https://mywiki.wooledge.org/BashFAQ/028 this will explain why it's not recommended to use $0
- myuzio 4y agoThanks for sharing. The only actual useful thing I got from this post.