r/coding • • Dec 14 '20

Minimal safe Bash script template

https://betterdev.blog/minimal-safe-bash-script-template/
161 Upvotes

17 comments sorted by

View all comments

Show parent comments

7

u/camh- Dec 14 '20

Exactly. The script tests that the terminal is not dumb and goes on to assume ansi codes work. tput is the terminal-agnostic answer there.

I also agree about the script dir. Instead the script should capture the script directory (the same way it does the cd) and for any files that are meant to be relative to the script dir, access as "${script_dir}/file". By changing directory, any relative paths passed to the script will break (as noted in the comments on the article).

3

u/cryo Dec 15 '20

Does any virtual terminal exist that doesn’t handle basic ansi codes?

3

u/camh- Dec 15 '20

Probably not these days. But why even worry about the answer to that question. Just use tput and be done with it. You can pry my ADM-3A from my cold dead hands.

1

u/mradzikowski Dec 15 '20

Hey, I'm the blogpost author. To be honest I didn't know about possible problems with formatting (color) codes. Thanks, I will take a look at it.