In-reply-to » @kat my terrible script https://bytes.4-walls.net/kat/dotfiles/src/branch/main/scripts/Scripts/tinypin-log.sh

@kat@yarn.girlonthemoon.xyz You don’t need to change the directory first in line 11, you can just create the directory, that’s sufficient since you’re having an absolute path.

The echo in line 13 is useless, you can simplify this to: newdir="$WD/$now" If you reversed this line with the previous one, you could make use of the variable in the directory creation: mkdir "$newdir".

In line 16, pull the directory change out of the loop upfront. The loop body doesn’t modify the working directory, so no need to reset it with each cycle. In fact, you could even spare the cd altogether when you simply tell find where to look: find "$basedir" -type f….

I didn’t try it, but if I read the manpage correctly, you should be able to simplify line 19 as well:

-C Change to DIR before performing any operations. This option is order-sensitive, i.e. it affects all options that follow.

Hence, remove the cd and put the -C "$WD" as the first argument to tar. Again, I didn’t try it. Proceed with caution.

Finally, you don’t need to specify the full path to rm in line 21. I bet, /bin is in your PATH. When you removed the previous cd from my last suggestion, the relative path that follows won’t work anymore. So, just use the absolute path that you already have in a variable: rm -rf "$newdir"

I hope you find this tiny review a wee bit useful. :-)

⤋ Read More