Replies: 8 comments 1 reply
-
awesome ideas I will defo take your advice and switch some of the stuff that needs cleaning up I'm pretty new (4 months) at pure bash and use to use coreutils way too much for bash stuff |
Beta Was this translation helpful? Give feedback.
-
@terminalforlife i did try this and it came back with nothing? is there something im doing wrong? it seems to work in a script on its own but not inside the bash script itself
edit removing set -e seems to have fixed this issue |
Beta Was this translation helpful? Give feedback.
-
Oh, glad it's sorted now. Personally, I don't recommend using There are similar arguments in PERL land too, where some will recommend against BTW, that usage output is far too wide, requiring a rather large terminal to view the output properly. Try to keep all standard and error output given to the user within 80 columns. You want things to be presentable and easy to read for as many users as possible, after all. |
Beta Was this translation helpful? Give feedback.
-
i really dont understand would it be like
|
Beta Was this translation helpful? Give feedback.
-
Ah, so, the [[ ! "$yn" = "y" ]] && exit Yes, except I would enter: [[ $REPLY == y ]] || exit The Please, please avoid double-negatives in your logic! It's a huge no-no, because it unnecessarily confuses the reader. Think of it this way: your initial approach was saying "if it's true that it is not true" when you could instead just say "if it's not true". Actually, technically speaking, the way you phrased it was "if it's true that it's not true that it's true", because of where you placed the negation. Lol Sometimes a double-negative is unavoidable, but most of the time I find it's easily avoidable. BTW, regarding |
Beta Was this translation helpful? Give feedback.
-
cheers got it working well with most of these improvments :) |
Beta Was this translation helpful? Give feedback.
-
yet so clean in vim its doing my head in |
Beta Was this translation helpful? Give feedback.
-
That's because of the tabs. Use whitespaces within the actual heredoc, except of course any leading tabs which |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hope this is what you had in mind. :) I'll comment at the top of each snippet. You might want to reference this issue in any commits which might address this issue.
Is there a specific reason for this line? Because if
$HOME
is empty, then you won't get anything from~
anyway, so I'm 99.9% sure this is a redundant line. I tested this just now, withHOME=
followed byecho ~
and got nothing, as expected.https://github.com/The-Repo-Club/proctl/blob/4cd9e91dc413b720ff34579151617867298cebe8/proctl#L25
I recommend using the
type
builtin over thecommand
builtin for dependency checking, becausetype -P
will only look in$PATH
for executables, whereas the old-school approach you used can pick up other things, like functions. Unless you're reckless with your names, this probably won't be an issue, but I do think it's probably one of those 'good practice' situations.https://github.com/The-Repo-Club/proctl/blob/4cd9e91dc413b720ff34579151617867298cebe8/proctl#L27
I strongly recommend against using aliases in a script, despite how clean it can look. Unless it's your BASH configuration, of course. You cannot rely on the user having aliases available in their BASH installation, and it would likely lead to confusion on the reader's part, because it's surely unexpected in a program/script.
I do appreciate you thinking out of the box though, and it certainly does look concise.
https://github.com/The-Repo-Club/proctl/blob/4cd9e91dc413b720ff34579151617867298cebe8/proctl#L43
You wish to escape the escapes? Parameter expansion's pattern substitution would've sufficed here, which would also be much more efficient. IE:
https://github.com/The-Repo-Club/proctl/blob/4cd9e91dc413b720ff34579151617867298cebe8/proctl#L61
Personally, and I suppose 'in my opinion', I find that if I'm needing to use
-maxdepth N
in a script with find(1), then I shouldn't be using find(1) for that task, unless it's just a quick-'n'-dirty thing. This is because you're loading up the find(1) program unnecessarily. Here's what you could do with the shell itself, with minimal effort:What about
-L
? You might ask. Well, I don't understand why following links even makes sense in this case, because you're not working recursively. Have I missed something? If not, then I think this function would be better.If you need to include hidden files, use
{.*,*}
.Same goes for both functions, but TBH, if I were writing this, I wouldn't have written two functions which do essentially the same thing — I'd have written one function which could do both, by using a flag of some sort; it would've saved repetition.
This possibly would've been a good opportunity to use indirect expansion using a name reference (nameref).
https://github.com/The-Repo-Club/proctl/blob/4cd9e91dc413b720ff34579151617867298cebe8/proctl#L65-L67
This could've been much easier with a heredoc; it would've saved you a lot of hassle, then and in the future.
If only you used tabs:
So much cleaner and so much easier to work with!
https://github.com/The-Repo-Club/proctl/blob/4cd9e91dc413b720ff34579151617867298cebe8/proctl#L69-L100
Again, this could've been so much nicer, cleaner, easier to work with, and, much like the above
usage()
, even a bit more efficient, if you used tabs:It's things like this which have me wondering why people poop all over tabs, in programming. If you're a Vim user, you can
:set tabstop=2
and you're good to go. :PBTW, I recommend using variables for paths more often, at the very least, if you plan to reuse them. Like in this case, I found a few instances where that same path was used. It's just what I'd consider 'good practice' because it avoids (potentially disastrous) bugs as a result of typos and it makes it easier to change these things in the future.
https://github.com/The-Repo-Club/proctl/blob/4cd9e91dc413b720ff34579151617867298cebe8/proctl#L112-L128
Instead of separately printing and then reading from STDIN, you can combine the two, which is also more ever so slightly (lol) more efficient — you're in BASH, after all:
You probably also don't want to use the
-r
flag all the time, despite how people will often tell you to, unless of course you're planning to parse escape sequences provided by the user. While it's probably benign here, it's a flag you will likely rarely actually need, so that'll save you a couple of key-strokes.As I say: "use what you need"
https://github.com/The-Repo-Club/proctl/blob/4cd9e91dc413b720ff34579151617867298cebe8/proctl#L142-L143
Quite a bit of an optimization, and to make it much clearer:
Why?
exit
-s weren't as clear as they probably should've beenActually, regarding the subshells, I believe you exited from those subshells, meaning you weren't exiting from the program itself, which is presumably what you wanted, so that was a probably a bug.
It's at this point I'd suggest something to replace sed(1), because I suspect that's not needed, but...
https://github.com/The-Repo-Club/proctl/blob/4cd9e91dc413b720ff34579151617867298cebe8/proctl#L176-L182
It's getting super late and there is a lot to get through here, so I'll try to resume this tomorrow, if I get the chance. I hope this stuff was helpful! Maybe it'd be better to do this in chunks. Let me know what you think. If you disagree with anything, that's okay. :)
Beta Was this translation helpful? Give feedback.
All reactions