Hot answers tagged

22 votes

"Up" script for moving up directories quickly

This is a decent concept, but by looping on the cd you loose some of the value of the $OLDPWD function in the shell. For example,...
user avatar
  • 96.7k
17 votes
Accepted

Bash Music Player 2

You completely ignored the first points from the review your earlier question, and they still apply here: Whitespace is not a precious resource: your code is far too dense for my taste ...
user avatar
  • 107k
16 votes
Accepted

"Up" script for moving up directories quickly

Your recommendation is to define alias up=". path/to/up" so that when you type up 3, it expands to ...
user avatar
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 ...
user avatar
  • 1,203
15 votes
Accepted

Create New C++ Class

Use input redirection instead of cat | ... Instead of cat somefile | somecommand, you should use input redirection, for example:...
user avatar
  • 107k
15 votes
Accepted

SSH passing your Public key to all the users on remote host

That looks crazy. But some constructive comments: Did you check for ssh-copy-id script, that is usually shipped with openssh? ...
user avatar
  • 268
15 votes

JSON Parsing in Bash

Bash is not well-suited for transforming JSON. But jq is. But calling jq 3 times for each line of input is certainly going to be ...
user avatar
  • 107k
14 votes

Discover random web servers and print the index page title

Overall, the code is pretty clean. Some notes about the Python part: be consistent about the documentation string style - enclose them with triple quotes, start with an upper-case letter, end with a ...
user avatar
  • 17k
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. ...
user avatar
  • 2,671
13 votes
Accepted

Calculating pi using bash

I see a few things that could allow you to improve your program. First, though, I don't consider myself a bash expert, so there may well be better ways of doing these things. Use a "shebang" line ...
user avatar
  • 64.4k
13 votes
Accepted

Bash script to simplify Git deployment workflow

Use exit codes directly Instead of this: merge $SOURCE_BRANCH 'staging' status=$? if [ $status -ne 0 ] then echo "ERROR: STEP 1" >&2 exit 1 fi You ...
user avatar
  • 107k
13 votes

Getting the current IP from the command line

I would use a different service that provides output in a format that is good for tools (not humans (html is for displaying for humans)). Hit this url: ...
user avatar
  • 91.7k
13 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 ...
user avatar
  • 91.7k
12 votes
Accepted

Setting up a development environment

Simplify Since $# cannot be both 0 and 1 at the same time, it would be better to join the two if conditions here: ...
user avatar
  • 107k
12 votes
Accepted

Guessing the JDK home directory

Variables The line containing the JDK_ROOT_DIR=( … ) definition is so long that it's unreadable and unmaintainable. In fact, you listed ...
user avatar
11 votes
Accepted

Bash script for getting geolocation (latitude, longitude and country code)

Bugs: echo "$my_variable" | my_command can behave unexpectedly if the variable starts with one of the echo options. You can do <...
user avatar
  • 8,737
11 votes
Accepted

Securely delete a file

Concept Review There are a number of purpose built tools to do this job already. The one that comes to mind first is 'shred'. shred is installed by default on all Redhat and Ubuntu systems (in ...
user avatar
  • 96.7k
11 votes
Accepted

Text centering function in bash

Since you are using printf to output the spaces, you may as well use a specific printf format for the output. Here's a replacement function: ...
user avatar
  • 96.7k
11 votes

"Up" script for moving up directories quickly

200_success's answer uses the evil eval which in his context was unnecessary. Update: Oh, what, bash? Let's use some brace expansion + evil things: ...
user avatar
11 votes
Accepted

Bash script that lowercases files

In my testing, constructing one Perl script and running it repeatedly is much faster (0.5s versus 3.6s) then running a new Perl instance for each replacement: ...
user avatar
  • 1,338
11 votes

Disallow `rm` to remove `*`

The vulnerability I see is that only the first two arguments are checked. You could check all of them: ...
user avatar
11 votes
Accepted

Parallelized for loop in Bash

Some suggestions: The trailing slash in the mkdir command is redundant. $(…) is preferred over backticks for command ...
user avatar
  • 8,737
11 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 ...
user avatar
  • 5,262
10 votes
Accepted

Shell Script (Bash) to sum multiples of different arguments below a number

Arithmetic operations If you look closely, something is a bit odd here: for (( i = 0; i <= $limit; i+=$1 )); do Ideas? How about: ...
user avatar
  • 107k
10 votes
Accepted

Getting the current IP from the command line

Your code is fine, except for the stray method. POST at that point isn't valid, and you will try to connect to a server called ...
user avatar
  • 18.8k
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 ...
user avatar
  • 107k
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()...
user avatar
  • 22.3k
10 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 ...
user avatar
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 ...
user avatar
  • 1,081
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.4k

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