Skip to main content
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 ...
jpmc26's user avatar
  • 1,243
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. ...
chicks's user avatar
  • 2,889
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 ...
Loki Astari's user avatar
  • 97.7k
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 ...
Kate's user avatar
  • 8,303
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: ...
Oh My Goodness's user avatar
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 ...
l0b0's user avatar
  • 9,117
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. ...
Countingstuff's user avatar
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 ...
Konrad Rudolph's user avatar
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 ...
janos's user avatar
  • 113k
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()...
Martin R's user avatar
  • 24.2k
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 ...
Lev M.'s user avatar
  • 1,081
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....
200_success's user avatar
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 ...
chicks's user avatar
  • 2,889
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 ...
Toby Speight's user avatar
  • 88.3k
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 ...
janos's user avatar
  • 113k
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 (...
janos's user avatar
  • 113k
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, ...
janos's user avatar
  • 113k
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 ...
Oh My Goodness's user avatar
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....
Toby Speight's user avatar
  • 88.3k
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. ...
that other guy's user avatar
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 ...
Toby Speight's user avatar
  • 88.3k
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 ...
hjpotter92's user avatar
  • 8,921
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 ...
l0b0's user avatar
  • 9,117
8 votes

Custom hash function as Bash script

How would you rate it? Obscure. This does not impress me as a supportable codebase. ...
J_H's user avatar
  • 42.1k
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 ...
Toby Speight's user avatar
  • 88.3k
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?" "...
thiagoalessio's user avatar
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) ...
hjpotter92's user avatar
  • 8,921
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, ...
janos's user avatar
  • 113k
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: ...
Toby Speight's user avatar
  • 88.3k
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: ...
Toby Speight's user avatar
  • 88.3k

Only top scored, non community-wiki answers of a minimum length are eligible