Hot answers tagged

9 votes

Optimize bash script that concatenates output

do ... done is a compound command; every subcommand shares the file descriptors; so teeing the the loop has the same effect as <...
user avatar
  • 53.8k
8 votes

Fizz having an argument with Buzz

Two points: echo $(something that already prints) is just redundant. This is simpler source ./buzz.sh $i There does not ...
user avatar
7 votes
Accepted

Replacing values in json file with jq

Accessing environment variables in jq This doesn't really work as it is...: ...
user avatar
  • 107k
7 votes
Accepted

Fizz having an argument with Buzz

If you're using source, you shouldn't have the shebang in the second script. If you're using the shebang, you shouldn't use ...
user avatar
  • 1,061
7 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 ...
user avatar
7 votes

Updating text in a HTML document with Bash

Your code seems pretty much fine, and chicks has pointed out most of the issues I have. It's not a bad implementation of the approach you've chosen, but I have to wonder if that's the right approach. ...
user avatar
  • 2,628
6 votes
Accepted

Interactive Linux upgrade script

2018/04/24 edit I missed an obvious bug: is_linux_mint is not implemented correctly. The results of a return on an empty output of a command substitution, with or ...
user avatar
  • 880
6 votes
Accepted

Updating text in a HTML document with Bash

Good great variable names, but I quibble over a couple later on nice use of blank lines to organize code appropriate use of sed. (Regex search and replace is the ...
user avatar
  • 2,706
6 votes

Updating text in a HTML document with Bash

One thing you might choose to do, given the neat correspondence of variable names and element ids, is to generate the sed script from the list of variables: ...
user avatar
  • 58.1k
5 votes
Accepted

POSIX shell script using a string to store command arguments

First thing, you could turn the check if the checkbashisms tool is installed into a guard clause, shaving off one level of indentation: ...
user avatar
5 votes
Accepted

Check disk space against a threshold

Using a string for MOUNTPOINTS means you can't have any mount points with spaces of glob characters in the names. I realize you likely can't use an array if you ...
user avatar
5 votes
Accepted

Finding (and counting) duplicate JS/Java files

Aside from running essentially the same find command three times, the main issue is that you run a separate basename instance ...
user avatar
  • 223
5 votes

Count line of code for a JavaScript project

General Run shellcheck on this script - almost all variable expansions are unquoted, but need to be quoted. That will also highlight the non-portable ...
user avatar
  • 58.1k
4 votes

Bash script that checks if font is installed and installs it if necessary

If you are using bash then rather than mixing [ and [[, you should stick with one or the other, preferrably ...
user avatar
4 votes
Accepted

Shell script for creating CR questions

I note three potential problems with your approach, both dealing with special characters in filenames, as well as one comment on the example usage. for with ...
user avatar
  • 1,717
4 votes

Shell script to detect router slider status

First of all, there are so many pitfalls associated with /bin/sh programming that I prefer to write all except the most trivial scripts in a language like perl, ...
user avatar
  • 1,885
4 votes
Accepted

An installer for shell scripts, written in pure sh

I see a number of things that may help you improve this program. I don't have a Windows machine handy, so these will all be Linux-based observations. For local installation, don't use ...
user avatar
  • 64.5k
4 votes

A replacement for OSX's path_helper

As to the security of this: if [ -x /usr/local/libexec/path_helper ]; then eval `/usr/local/libexec/path_helper` fi This runs the ...
user avatar
4 votes
Accepted

Shell script to create a boilerplate proyect

I'm not a shell expert, but I think I could help a bit. The most relevant tips I could give are: 1. Quote your expansions Unquoted expansions are the most common source of bugs and security issues ...
user avatar
  • 176
4 votes
Accepted

Shell POSIX OpenSSL file decryption script

Get rid of unnecessary nested and combined ifs While here it goes to no extreme, it's advisable to check for errors first, and to do that one by one - if possible, ...
user avatar
4 votes
Accepted

Arch linux installation script to be reviewed for any leakage of personal / security info

Some notes: This script is really very brittle. It'll break if any of the tools change in any significant way, if your disk layout changes (see below), or if the sequence of steps for whatever reason ...
user avatar
  • 8,737
4 votes
Accepted

Replace version numbers in multiple files

A shell program ought to begin with an interpreter specification: #!/bin/sh It looks like oldVersion needs to be a regex, but <...
user avatar
  • 58.1k
3 votes

Process monitoring script

Don't write custom scripts for common sysadmin tasks. Using the proper tools will get the job done better, and the solution will be more maintainable — especially by any colleagues you might have. ...
user avatar
3 votes

Simple import system for a large shell program

I don't have enough reputation to comment, but I am rather intrigued by your script, because I also enjoy writing large programs in the shell, and recently have been trying write modular shell scripts....
user avatar
  • 61
3 votes
Accepted

Disable reboot on control-alt-delete for RedHat/CentOS 5/6/7

That's a four calls to cat /etc/redhat-release. A case statement could help reduce the clutter: ...
user avatar
3 votes

Check disk space against a threshold

The other answers made very good points, in the following I will mention only what was missed. First of all, don't be afraid to use Bash instead of /bin/sh. Bash ...
user avatar
  • 107k
3 votes

Check disk space against a threshold

There are a number of concerns I have here, some of them style related, but mostly about the actual functionality.... mounts /var and ...
user avatar
  • 96.8k
3 votes
Accepted

Bash script that checks for package dependencies and installs them if necessary

Instead of this: if [ $(dpkg-query -W -f='${Status}' $i 2>/dev/null | grep -c "ok installed") -eq 0 ]; then A better way to write the same thing: ...
user avatar
  • 107k
3 votes
Accepted

Split redirecting to multiple files in bash

There are a number of things here which concern me. First up, the stderr log file does not have the time on the file name (missing _%T). This is a classic copy-...
user avatar
  • 96.8k
3 votes

Bash script to rename subfolder to include name of parent folder

You should always double-quote variables that are used as filesystem paths. This is the same script but with variables correctly double-quoted: ...
user avatar
  • 107k

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