16
votes
Accepted
Git delete all merged in local branches
Improve your file handling:
Don't use a hard coded file name for temporary files.
Don't spew temporary files into the current directory.
Make sure you clean up temporary files even on error.
The first ...
14
votes
Git delete all merged in local branches
DRY - don't repeat yourself
"Don't repeat yourself" is a popular programming principle. You could apply it here by not repeating your filename over and over.
...
14
votes
Git Push Bash script
Rather than make it interactive
read -p "Continue? " yn
I would make this more like other command line tools. You have default values and allow ...
13
votes
Accepted
Bash script to automate dev environment setup
I think you could benefit from using Ansible in this scenario then you can easily deploy your configuration to other machines and you will have learned a valuable IT skill.
And rather than use bash ...
12
votes
Disallow `rm` to remove `*`
The vulnerability I see is that only the first two arguments are checked. You could check all of them:
...
12
votes
Accepted
Parallelized for loop in Bash
Some suggestions:
The trailing slash in the mkdir command is redundant.
$(…) is preferred over backticks for command ...
12
votes
Bash script to automate dev environment setup
First of all, I would suggest using shellcheck when writing bash https://www.shellcheck.net/, it will point out many many errors, some trivial and some not so trivial.
...
11
votes
Accepted
Installing GNOME extension via CLI
First off, install Shellcheck and routinely run it on your scripts, or configure your editor to run it automatically. Now, Shellcheck is pretty rigorous and you would be forgiven for not solving all ...
10
votes
Accepted
Bob Marley is jamming on the wifi
Nothing would make a reviewer happier than help you jam the networks of an innocent neighborhood. (sarcasm)
Mutually exclusive conditions
Can line match ...
10
votes
Backup with Hanoi Strategy
Do not silently ignore invalid arguments
Your script allows to specify the source directory (and other locations). Here is the relevant part in function parseArgs()...
10
votes
Wi-fi scheduler written in C
I will offer some suggestions.
Please note I have no experience with Mac OS, but I believe most of it will still apply.
Using system is not particularly bad in ...
9
votes
Accepted
Bash script to truncate subject line of incoming email
Be sure to read the relevant RFCs that govern e-mail headers! Specifically:
RFC 2822, Section 1.2.2: Header names are case-insensitive.
RFC 2822, Section 2.2.3: Header fields may be line-folded:
2....
9
votes
Accepted
Weekly MySQL database backup
Overall
This is totally decent code and not too difficult to maintain. Your variable names make sense and you've made some effort at not repeating yourself, other than the lack of a loop which you ...
8
votes
Accepted
Bash script to temporarily run a shell without certain group memberships
It's not an error to ask for help
When -h is passed, the help() function shouldn't exit with non-zero status, because it's done ...
8
votes
Accepted
Upgrade Firefox Quantum from tarball
Pretty nice script, I have mostly minor suggestions.
Always double-quote variables used in command arguments
The parameters in these command should be double-quoted to protect from word splitting ...
8
votes
Disallow `rm` to remove `*`
Double-quote variables used in command parameters
This is a bug:
/bin/rm -i $@
What will happen if you try to delete file a b (...
8
votes
Backup with Hanoi Strategy
Double-quote variables used as command arguments
Although in many places in the posted code the variables used as command arguments are correctly double-quoted, there are more than a few exceptions, ...
8
votes
Accepted
Count line of code for a JavaScript project
fileExt="*.js"
allFiles=$(find ./ -name $fileExt)
This is a bug. The wildcard in $fileExt will be expanded by the shell, and ...
8
votes
Prefix all lines on standard error
There's not a lot to review here. It's Valgrind clean, though that's not difficult to achieve.
Certainly consider closing stream 3, unless you want to keep a means to emit unprefixed stderr messages....
8
votes
Test to see if installed and if not, install it
Overall it's fine. My suggestions would be:
Fix the indenting.
If you find the comments helpful, great. Otherwise, consider saying "why" and not "what", e.g. ...
8
votes
Test to see if installed and if not, install it
In addition to the excellent answer by that other guy:
It's a good idea to start the script with a shebang specifying which interpreter to run. In this case, we're not using any Bash features not ...
8
votes
Compare all files to each other
Welcome to Code Review!
Shellcheck
Use the amazing shellcheck utility to verify for common practices when writing bash/shell scripts. It reports missing shebang.
Loop using seq
Since you know the ...
8
votes
Accepted
Daily stand-up list
Some suggestions:
#!/usr/bin/env bash is a more portable shebang line.
I would use long options for set and ...
8
votes
Custom hash function as Bash script
How would you rate it?
Obscure.
This does not impress me as a supportable codebase.
...
8
votes
Accepted
Custom hash function as Bash script
I see no evidence that this is a cryptographically-strong hash function. You should include a comment that links to a reputable reference for the algorithm you are implementing, so that reviewers can ...
7
votes
Accepted
Script to create symlinks for dotfiles in a Git repository
I noticed that some of your questions have similar aspects, so I clustered them to provide a single answer:
"How is my general bash programming style?"
"How can I reduce the number of duplicates?"
"...
7
votes
Git delete all merged in local branches
I am assuming you are starting nano so that you may remove possible occurrences of master branch (or some other static branch) ...
7
votes
Interactive bash script to create new permanent swapfiles
Portability
You mentioned portability as one of your top concerns.
The commands used by the script limit it to certain systems:
swapon, ...
7
votes
Script to clean up old files that should only run one instance
General impressions - nice neat code, well commented. It's good that you use trap to clean up on exit.
Shellcheck picks up a couple of oversights:
...
7
votes
Bash script to truncate subject line of incoming email
Generally good code - plus points for good use of stdout/stderr and exit status.
Shellcheck reported some issues:
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
bash × 834linux × 196
shell × 188
beginner × 98
performance × 42
file-system × 40
git × 39
installer × 39
awk × 36
sed × 35
console × 34
sh × 33
security × 25
unix × 24
macos × 24
python × 20
parsing × 20
networking × 16
c × 14
mysql × 14
amazon-web-services × 14
ssh × 14
regex × 13
curl × 13
wordpress × 12