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,...
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
...
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 ...
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 ...
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:...
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? ...
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 ...
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 ...
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.
...
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
...
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 ...
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:
...
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 ...
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:
...
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 ...
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 <...
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 ...
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:
...
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:
...
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:
...
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:
...
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 ...
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 ...
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: ...
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 ...
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
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
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
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 <...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
bash × 770linux × 184
shell × 171
beginner × 90
performance × 42
git × 40
file-system × 37
installer × 37
awk × 34
sh × 31
console × 30
sed × 30
security × 25
unix × 24
macos × 24
parsing × 20
python × 19
networking × 14
amazon-web-services × 14
c × 13
mysql × 13
regex × 13
ssh × 13
wordpress × 12
datetime × 11