Skip to main content
Share Your Experience: Take the 2024 Developer Survey
21 votes
Accepted

Yet another shell in C

You wrote a nice and simple shell. It works for very simple commands but fails on more complex ones (for details, see below). The code can be cleaned up in several places. To make your code nicely ...
Roland Illig's user avatar
  • 21.3k
18 votes

Shell script to compile Java

Using custom shell scripts is not a typical way to compile and package multiple source files into a Jar-package. The de-facto standard tools for building Java projects and managing their dependencies ...
TorbenPutkonen's 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 ...
jpmc26's user avatar
  • 1,233
15 votes
Accepted

Shell script to compile Java

No #! line to specify interpreter. Perhaps not so important for something that's portable shell, but still helpful to write ...
Toby Speight's user avatar
  • 75.7k
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,863
8 votes
Accepted

Basic shell in C

Avoid a hacker exploit: What happens when the first character read is a null character? ...
chux - Reinstate Monica's user avatar
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

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
  • 75.7k
7 votes
Accepted

Memoizing or caching Bash function results

This looks very slick! I've tried it on a few things, and it speeds up very slow commands quite a bit. Less-slow commands, as you've noticed, are still a bit expensive. A few preliminary thoughts (I'...
Zac B's user avatar
  • 186
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,716
7 votes
Accepted

Bash script to check available name in Github

The code is nice and short, and it is easy to read. I'm surprised that it works at all. Sending the out=$(…) command to the background sounds as if the code might ...
Roland Illig's user avatar
  • 21.3k
7 votes

Interactive shell for Arduino

#define Don't use #define for constants! #define MAX_COMMAND_SIZE 30 should be: ...
JDługosz's user avatar
  • 11.4k
6 votes

Memoizing or caching Bash function results

The review by Zac B is very nice, I have only minor comments on top of that about the implementation. Large scripts in here-documents Escaping $ in large here-...
janos's user avatar
  • 111k
6 votes
Accepted

PS1 for Bash prompt showing last exit status, written mostly in Python

As I write, there are already two good answers, the first, by Janos and a supplement, by Aaron Hall. This stands as a further supplement, and should be read in conjunction with the others. There's ...
Toby Speight's user avatar
  • 75.7k
6 votes
Accepted

Append a note to one of three files based on user choice

A couple of points: You determine the date outside your loop, then loop forever. Every note you make after the first one is going to have the same date stamp. A better approach would be to collect ...
aghast's user avatar
  • 12.4k
6 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 ...
Toby Speight's user avatar
  • 75.7k
6 votes
Accepted

NRPE script for monitoring load average

This looks pretty good. Some suggestions: [[ is preferred over [ in Bash. This script could benefit from ...
l0b0's user avatar
  • 8,927
6 votes

Inserting command output into multiline string

If GUAC_PASSWORD is a string like -e foo or /etc/*, that's going to create problems. ...
Oh My Goodness's user avatar
6 votes
Accepted

The Blacklist -- Follow-Up 2: Electric Boogaloo

You might want to check again the link you've provided: on 2023-10-12, it is strictly valid JSON and as such you can remove the jq -n -f part completely. That ...
sparrowolfhawk's user avatar
6 votes
Accepted

Print full path to last modified file in a given location

I would like to remove the duplicated command. ...
glenn jackman's user avatar
6 votes

Print full path to last modified file in a given location

Test argument count Testing [ -n "$1" ] is a failure if we're running with set -u (and I do recommend ...
Toby Speight's user avatar
  • 75.7k
6 votes

A shell function to copy files and directories, preserving directory structure

UI / design I respectfully reject the premise that this is an improvement on rsync. For an "easy" copy, almost any tool will be adequate, including ...
J_H's user avatar
  • 27.5k
6 votes
Accepted

Update a docker compose service properly

Your manual approach, using a single docker container, sounds like it is routinely accompanied by a brief outage as you switch to a new rev of code. Is this a common way No. can I update it in the ...
J_H's user avatar
  • 27.5k
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: ...
Anselm Helbig's user avatar
5 votes
Accepted

Creating a struct

Mixed use of array indexing with unsigned and int. size_t should be used. Rather than ...
chux - Reinstate Monica's user avatar
5 votes
Accepted

My Pythonic take on Psexec

Keep your imports grouped. From PEP 8. Imports should be grouped in the following order: standard library imports related third party imports local application/library specific imports ...
Ashwini Chaudhary's user avatar
5 votes

PS1 for Bash prompt showing last exit status, written mostly in Python

The typo If we look at the beginning and the of the posted code: ...
janos's user avatar
  • 111k
5 votes

PS1 for Bash prompt showing last exit status, written mostly in Python

Improvements on Janos's answer using tput to yield the escape codes for cross-platform compatibility wrapping the escape codes in ...
Aaron Hall's user avatar
  • 1,568
5 votes

A basic Object Orientated REPL Implementation

Looks quite good to me! There's some things I think you could improve: When a user hits Ctrl-C, the program flow is suddenly interrupted. The call to sys.exit ...
Daniel's user avatar
  • 4,490

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