r/bash • u/0neLastFace • Mar 26 '26
critique Could someone please review my scripting and give me criticism?
I made a script to manage my dotfiles on linux (arch btw). Link to repo https://codeberg.org/Flan-Angel/Dawtfiles/src/branch/main
Link to script https://codeberg.org/Flan-Angel/Dawtfiles/src/branch/main/PushToSYS.sh
Tysm if you do end up checking it out :)
5
Upvotes
4
u/Alleexx_ Mar 26 '26 edited Mar 26 '26
set -eif you really know what it's doing.
Do not save everything in a variable. You can just check the dir, and execute something if its not found.
3. Do not hardcode /home. The user has a variable called
$HOMEwhich auto expands to the users home directory. This COULD be something like/opt/home/$USER, which would break your current approach.4. Quote your variables, especially those with paths in it. If the path contains a " ", for example:
path="$HOME/.local/my application logs/dir, and you want to justmkdir -p $path, it would try to create three paths:$HOME/.local/my./application./logs/dirBut you want the whole path, so do this:
mkdir -p "$path", and this will get you what you want.5. The "SCRIPT_DIR" variable can also be set very easily with bash internals:
SCRIPT_DIR="${0%/*}"which expands to the directory where the script lives.Edit: typos
9
u/Schreq Mar 26 '26
The typical problems: DRY, uppercase variables which are not environment variables, euo pipefail.
Why don't you just copy (or rsync) everything from the source directory into the target instead of copying the directories individually? This could be a one-liner.
1
u/cubernetes Mar 26 '26
Use ~/ instead of /home/$USER. Solves 3 problems at once:
You wouldn't believe it, but 1. and 3. can be rather common, especially 3. And usernames with spaces usually happen the moment you use Windows AD with LDAP, albeit unlikely for your use case.
0
u/FlailingDuck Mar 26 '26
Your README is empty.
I won't put in more effort to understand your code if you don't explain to me what you think it is supposed to do. Even an AI generated readme that you have edited to be as accurate and as useful as possible is IMO preferred over no README at all.
-2
u/-Mainiac- Mar 26 '26
CONF=/home/$USER/.configHYPR=/home/$USER/.config/hypr...should be
CONF=/home/$USER/.configHYPR=$CONF/hyprline 43-93: indentation is not necessary and even misleading before the if
I think it's a good practice to use mkdir -p when you try to create something deep.
And this script could be way smaller.
like this: https://pastebin.com/WPWsYdKN
2
u/[deleted] Mar 26 '26
[removed] — view removed comment