Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [bash]

BASH is the GNU Bourne Again SHell, the successor to the classic Unix Bourne sh (shell). It's the default shell for various GNU systems.

9
votes
2answers
445 views

Parallelized for loop in Bash

I am using a Bash script to execute a Python script multiple times. In order to speed up the execution, I would like to execute these (independent) processes in parallel. The code below does so: <...
3
votes
1answer
24 views

Syncing GitHub repositories local, remote and forks

It's a simple bash script but I'm hoping for feedback, advice and examples on how to improve the script and code. Can you guide me how to put more checks in the code and more if possible? This code: ...
7
votes
1answer
34 views

Bash script to encode images in base64 and generate a CSS file from them

These are the first lines of code I've ever written. I've been interested in the idea of learning to program for quite a while, but never really pulled the trigger, and now I've been playing around ...
2
votes
0answers
33 views

Code to backup the history file in Linux

How is the logic, efficiency and can it be improved? This is a snippet from my .bashrc file; I just wrote it and I've tested it and it almost works. This was the ...
1
vote
1answer
60 views

Bash Code to backup the history file in Linux [closed]

How is the logic, efficiency and can it be improved? This is a snippet from my .bashrc file, I just wrote it. The code is supposed to do this: Backup my ...
9
votes
2answers
779 views

Count line of code for a JavaScript project

Here is my bash script that I just wrote to count line of code for JavaScript project. It will list number of: Comment lines Blank lines All lines Here is my script: ...
2
votes
2answers
51 views

Looking to shorten method of parsing arguments in BASH

I have here a working method of parsing input arguments however it seems redundant. I would like to shorten this code so it doesn't appear so repetitive. ...
3
votes
1answer
39 views

checksum hash verification functions for bash scripts

just a little script, or a bit of a template of one that I used to submit an assignment. I believe it all works fine, I just wanted to give it to other people, and get some feedback on it; maybe make ...
2
votes
1answer
26 views

shell library for Debian package releases

This is a bash library intended to be used in a CI/CD pipeline to make finding the next release number for a Debian package semi-automatic. I figured out how to ...
5
votes
2answers
49 views

Smart way to shorten the current working directory in pure Bash

I'm trying to create a shell prompt that displays the $PWD in a "smart" way. I want to display the top two directories rather than the full path. If ...
4
votes
1answer
62 views

Removing duplicate field entries from sorted csv data

Given the following input (cat i.txt), I want to remove duplicate field entries in each of the first three columns and none of the others. ...
4
votes
1answer
59 views

Shell script to calculate the total space consumed by a user by file-size

I'm working with a small bash code which is working fine but i'm just looking if there is better way to formulate this, In this code i'm looking for the Files between year 2002 and 2018 on the 7th ...
4
votes
1answer
67 views

Bash script to setup new Debian installs - follow-up

I have this bash script I've been working on and I have updated it. I was hoping for some advice and/or input on the code. This script is run directly after a fresh install of ...
2
votes
1answer
102 views

Create Apache2 virtualhost, Mysql db & user. CLI tool and GUI on top of it

Review for optimization, code standards, missed validation. What's in this version: Rewritten, instead of large complex script - few tools with each own task. Solid CLI tool and GUI script on top of ...
5
votes
1answer
83 views

Pure bash program for auto-filling a template file (Part 2)

This is my rewrite of the program posted here, based on janos's comments. I also added the ability to read from stdin. I've also included a test script. I wanted something lightweight I could ...
3
votes
1answer
46 views

Pure bash program for auto-filling a template file with ENV variables

Goal of Program Consider a template file template.txt with double brace variables, intended to be replaced by values: ...
5
votes
1answer
58 views

Batch upload users to nextcloud on docker with bash csv

I have this bash script that adds users to NextCloud from a csv file. It expects to be run from the same directory as the docker-compose.yml file. I'm pretty new to bash scripting and I'm wondering ...
3
votes
1answer
27 views

Local backup bash

The following code copy a complete folder (that has 3 folders inside), then check if errors are generated and send email if there's errors, the it proceeds to create 3 different tar files and finally ...
1
vote
1answer
21 views

Revised media ingest script

link to original question: Simple media ingest script As per answers I have refactored my code and would like to get feedback on the current structure. The purpose of this tool is to allow someone ...
4
votes
2answers
38 views

Simple media ingest script

Trying to script a simple command line tool for ingesting media to a target location following a structured naming convention. It's functional in its current state but I'd like to know if there are ...
6
votes
2answers
1k views

Backup with Hanoi Strategy

I want your suggestions about this shell script. I use it to backup some configurations on my home media server. What improvements would you do? Keep in mind, I want to optimize space and speed and ...
4
votes
2answers
55 views

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

The user selects one of the three categories then makes a note on that selection. Then the note is appended and saved to the appropriate list. It took me four hours to write this. I'm trying to learn ...
9
votes
5answers
165 views

Disallow `rm` to remove `*`

Note: If you googled this by the title of this question, don't use this script unless you know what it is supposed to do. This is a script in bash 3+ that I have ...
2
votes
2answers
70 views

Create Apache virtualhost, MySQL db and user, install option - desktop shortcut for GUI version

Review for optimization, code standards, missed validation and dependency checks. Review version 3. What's new: apply previous code review input arguments and validation MySQL management (optional) ...
2
votes
1answer
53 views

Bash on Synology - Delete recycle bin entries over X days old

Synology NASs have a Task Scheduler that allows you to schedule deletion of files over X days old from recycle bins. This feature isn't working for me–running the task results in no files being ...
1
vote
1answer
43 views

bash script - Create virtualhost on development server (ver 2)

Review compatibility, readability, good code standards, security. This is for development server, where webmaster uses GUI fo IDE and fine way to create quickly apache2 virtualhost using GUI but ...
5
votes
1answer
62 views

Simple bash script creates apache2 virtualhost config for subdomain

Simple bash script to create apache2 virtualhost for localhost. Can be used for public subdomains on developer server with changes - "replace .localhost". Tested on Ubuntu, but should work where ...
0
votes
1answer
24 views

Refactoring with many duplicates using Bash [closed]

I have a curl based working bash script, but I have many duplicates on the "CURL" body. How do I improve it efficiently to eliminate duplications? ...
8
votes
2answers
539 views

Bash script to truncate subject line of incoming email

I'm going to put this script into production in a mail server /etc/aliases file: we have a system that receives email but the subject line must be limited to a certain size. The proposed usage in the ...
1
vote
1answer
21 views

Install a Python package based on active_gpu or version [closed]

I have the following code, is there a way to optimize it/reduce the code? ...
0
votes
2answers
60 views

Bash Script for file auditing, push information to server and be able to view in a web page

Edit: The goal of this Question was only seeking code review and guidance in learning or tips for improvement. I apologize if that was not clear or aligned properly with the goals of this forum. ...
2
votes
2answers
41 views

Bash - Passing arguments with “$@” to either 'sudo su' or 'sh'

I have a server where shell commands to the supervisor-service must be executed by the specific user lx. I have written a bash function that does exactly that. <...
3
votes
2answers
51 views

Creating remote directories in a bash script via ssh (with error trapping)

I'd like to create directories on a remote VM, but only if they do not exist. What's more, if creating the directory results in an error (exit status != 0) I'd like the script to exit as well, or at ...
1
vote
1answer
38 views

Bash function to produce variants of images at 2X and 3X resolutions

I use ImageMagick to crop image, encapsulate the related code to functions. Here is the code: ...
3
votes
1answer
17 views

Tagging the directories and switching between them by tags - follow-up (Part 2/2: business logic)

This is the bash script responsible for changing the directories via textual tags. (See here the entire project.) dt_script ...
1
vote
1answer
27 views

Mac Bash: how to combine the open and str subtract to one line code? [closed]

new to bash , I use the following code to open the super folder with a file path. function openUp(){ cd $(echo $1 | sed 's@\(.*\)/.*@\1@' ); open .. } like ...
1
vote
2answers
27 views

Bash script to find included files in C code

I've got the following shell script (let say get_includes.sh): ...
3
votes
1answer
50 views

Bash script to backup a LAMP server

I wrote a bash script for backing up my LAMP server. To be honest that's my first experience in bash so I want to ask you for help in its improvement. ...
0
votes
2answers
44 views

“command preprocessing” with bash - string parsing and handling pipes [closed]

The following is a bash script named wrapper.sh: ...
4
votes
2answers
62 views

Upload a directory, in parallel, to an artifact repository

This code uploads an entire directory and allows for its reparenting on a remote server (an artifact repository). Three concerns: Copying the files locally takes a lot of space. Ideally, I could use ...
4
votes
1answer
66 views

Select second field in text table with shell script

I am writing a bash script to mount openshift service accounts into kubernetes objects. The right secret to use is highlighted in this text: $ oc describe sa sa-...
3
votes
2answers
88 views

Removing commented dead code without removing the legitimate comments

This question is the real question asked on StackOverflow. I'm here to review my answer and see how can I optimize it. Here is the answer text: This is a basic approach, but it proposes a proof of ...
4
votes
1answer
45 views

Bash function to find contents of a file with a certain extension

I have to read a lot of code and search through many code bases. I frequently find myself using something like grep -r --include=.C "test string" . to find files ...
3
votes
2answers
74 views

bash wrapper around 'git commit' to automatically bump (Python) package CalVer and create matching CalVer tag on new commit

I'm doing a lot of Python development lately for various (small-)data analysis pipelines at work. I've been wrestling with how to robustly and ~automatically version the code at a fine-grained level, ...
4
votes
2answers
60 views

Serial copying from disk images to folder in Bash

This is a Bash script that copies files stored inside disk images to a directory, using a defined structure provided via a JSON file. I've included the external programs it requires and the test I ...
3
votes
2answers
64 views

Code to get the IP address and format it to run in nmap

For scanning my subnet using my IP address, I need to run the following command nmap -sn 192.168.100.* I want to extend this functionality such that I don't have ...
3
votes
1answer
110 views

BASH Script to Configure Monitors on Linux via xRandR

My main computer is a laptop which I run i3wm atop Arch Linux. As such, my monitor situation sometimes changes, so I wanted to code a script to configure my monitors based on which ones are connected ...
1
vote
2answers
26 views

Bad performance bash, changing display brightness

I have a script that changes the display brightness using xrandr. It is my first bash script. I mainly had a lot of trouble with dealing with the floating point ...
2
votes
1answer
53 views

Simple bash argument parser

In a bash script, I need to parse arguments that have the following form: The main arguments can be thought of as being a single argument, but I do not want to force users to quote the entire thing, ...