Bugswriter / tuxi

Tuxi is a cli assistant. Get answers of your questions instantly.
GNU General Public License v3.0
1.33k stars 73 forks source link

Address a TODO, slightly optimize, and improve `check_deps()` #181

Closed terminalforlife closed 3 years ago

terminalforlife commented 3 years ago

Please refer to the commit messages for more information.

PureArtistry commented 3 years ago

cat into grep, what idiot wrote that!?!

I seriously over thought the the pipe bit (never wrote anything that takes piped input before), for some reason I assumed I would have to do while read then break after the first line just in case - I'm still very much a noob

learnt someting new about case statements though, I thought that if the statement could contain spaces or other breaking characters it needed to be quoted, I'm guessing that isn't the case?

terminalforlife commented 3 years ago

Word splitting typically doesn't occur in Bourne Shell and derivatives when there's a variable in:

Sorry if I've forgotten another exception, but that's all which comes to mind.

A "variable" also includes things like process substitution and command substitution. Static data such as a literal 'data here' does need to be quoted, but there's usually no need to test static data in this way.

If you're combining static data containing multiple words or data otherwise interpreted by the shell, with a variable, then you do need to quote the string, or at a minimum, the static part. IE: NAME="$HOME/cool path"

If you're compounding multiple variables in situations where word splitting ordinarily doesn't occur, then it still will not occur. This one boggled my brain for a while, and I honestly tend to quote them anyway, but it's technically not needed, so are wasted keystrokes. IE: NAME=$Data$MoreData

Bourne Shell (DASH) and BASH show the same result:

$ Data='really cool thing'
$ MoreData='other cool things'
$ CoolStuff=$Data$MoreData
$ printf '%s\n' "$CoolStuff"        
really cool thingother cool things

This is at least the case in Linux as I've known it for years. I'm grateful to the person on GitHub, whose name is unknown, who introduced me to the exceptions of word splitting.

Redundant use of cat(1), while painful, is a common mistake; we've probably all been there. :) Myself included!

PureArtistry commented 3 years ago

Thank you very much for the detailed explanation!

Bugswriter commented 3 years ago

@PureArtistry tell me when we have to merge the develop with main.