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.
836 questions
2
votes
0
answers
22
views
Bash tool for automating Telnet/SSH commands with live interactive session takeover
I made this executable because I used to play on a MUD, which was essentially a server to which you connect to through telnet to play in a multiplayer world. What annoyed me was how difficult it was ...
-1
votes
0
answers
48
views
Which design is better to handle timeout condition in Bash? [closed]
I am designing Bash functions that take a timeout argument. The question is, what would be the best way to notify the user that the operation has timeouted, as compared to normal or error condition.
...
0
votes
1
answer
185
views
Does an indentation style which uniquely identifies a column position to its role in the construct it belongs to make Bash code more readable?
What I'm asking here is whether do you think the facts
there is no type enforcing;
there is no indentation enforcing
consoles do not syntax highlight
consoles do not emphasize multi-line input a-la ...
6
votes
3
answers
821
views
Linux file encryption using GPG key
In the below script I am using some arrays, and other Bash stuff, but I have made a minimal working example for you, where you cannot see those things.
Anyway, I am interested in a review of the ...
8
votes
2
answers
477
views
Disabling local accounts on Azure Linux virtual machines
We’re enforcing Azure Entra authentication across all Linux VMs, so we’ll disable all local accounts via a custom script. The script will also create a single “break-glass” user with a randomly ...
8
votes
5
answers
448
views
Custom hash function as Bash script
I'm looking for a (possibly cryptographic strong) hash function in Bash with the following properties:
The input is only a string with 4 lower-case characters: aaaa to zzzz
The output should be a ...
8
votes
2
answers
301
views
Simple Node.js version manager
On Arch Linux, there are 2 packages that provide the Rust toolchain: rust itself and rustup. When users try to install a package ...
3
votes
1
answer
243
views
Script to fix filenames in the wrong encoding
If you have files with Cyrillic filenames (e.g. день) and pack them as a ZIP archive on Windows, and then unpack on Mac using the standard archive utility, the ...
7
votes
3
answers
319
views
lndir shell function - hardlink two directories
The code works, but I could use help testing it more comprehensively and double-checking that everything I'm doing makes sense, and that all the options can coexist with each other. I'm running into ...
5
votes
2
answers
152
views
Bash Script for Docker Image Cleanup
I’ve been working on a bash script to clean up old Docker images while keeping the latest tag for each repository and skipping images currently in use. I’m sharing the script below and would ...
1
vote
2
answers
151
views
Start screen lock for user from systemd
This is a script to start a screen lock in Ubuntu, with user customizable background image(s).
The script will eventually be run on sleep by systemd, so by root. This made it complicated to let the ...
1
vote
1
answer
62
views
Automating Arch Linux Installation with Custom Partitioning and Disk Setup
I'm trying to automate my Arch Linux installation using a bash script. The script would allow me to choose between installing Arch on a single SSD or using a combination of SSD (for root and home) and ...
3
votes
4
answers
173
views
Bash script to automate post install process on Fedora
The script runs fine, and it seems to be working correctly. I'm looking for some criticism of the structure of the code, errors, bad practices, beginner's pitfalls, and bad code in general.
I'm ...
8
votes
1
answer
723
views
Ask interactive user to respond yes or no
I've written a Bash function that can ask a simple yes/no question.
The "yes/no" prompt is translated to the user's language (the question must be localised by the caller).
Input is ...
1
vote
0
answers
109
views
Conflict-less Bash library function and variable naming
Marvelous Bash does not support built-in sufficient namespace features for functions or variables to specific file/module you would find in PHP or JavaScript.
Conflicts in global scopes, which are ...
5
votes
2
answers
109
views
Clean up and datestamp file names
I would like to ask for a review of the following Bash script which cleans up and datestamps file names, with an optional feature to rename the file.
The main use case is renaming files downloaded ...
2
votes
2
answers
81
views
Check if program has been installed successfully at a given path
The path is provided as an argument by a Makefile within an install target. The script verifies if the specified path is already included in the system's ...
3
votes
1
answer
69
views
Generating a Benchmarking Report for a Program
Objective:
The script should pass each file present in the data directory to the read_file executable, and print its result and ...
2
votes
1
answer
105
views
Text-based tic-tac-toe in bash (continued)
I wrote this two-player tic-tac-toe program in bash. To make a move, you enter a number between 1 and 9 which corresponds to the square:
...
6
votes
1
answer
234
views
Text based tic-tac-toe in bash
I wrote this two player tic-tac-toe program in bash. To make a move you enter a number between 0 and 8 which corresponds to the square:
0|1|2
3|4|5
6|7|8
This is ...
5
votes
2
answers
153
views
A shell function to copy files and directories, preserving directory structure
For a script, I came up with a shell function that might be generally useful. Before I add it to the code base, I’d like to hear someone’s opinion on this.
I don’t write shell scripts often and had to ...
1
vote
3
answers
114
views
Bash script to read csv, manipulate data, write csv
This is pretty horrible code, but it works. I don't code in bash 😭, usually code in Python.
This is a learning exercise for me, so that's why I'm using bash + that's why I don't use libraries.
I ...
4
votes
1
answer
78
views
Blocking lock for dpkg
My deployment and configuration process entails multiple processes trying to invoke dpkg on my VM at the same time. While dpkg has a locking mechanism, it causes anyone not holding the lock who is ...
1
vote
0
answers
74
views
Bash: executing a DAG of idempotent functions in topological order
Suppose that I want to subdivide a bash script into small idempotent functions, and I also want that those functions can depend on each other. For example, assume ...
3
votes
1
answer
436
views
Bash scripts to convert json to associative arrays and then back to json
I'm a relative bash novice but have found it along with jq a great way to manipulate json scraped from various sources. I couldn't find any ready-made scripts to convert arbitrarily deep json to bash ...
4
votes
1
answer
88
views
Advent of code 2023 day 9: Sequence extrapolation - in pure Bash
Part 1
Today's task involves extrapolating the next value in sequences, given in this format:
0 3 6 9 12 15
1 3 6 10 15 21
10 13 16 21 30 45
The task is to ...
3
votes
2
answers
67
views
Script to automate testing solutions
Here's a script I wrote to automate testing for multiple sample files across two solutions, aiming to streamline the process. The script, provided below, compares expected results with the output of ...
1
vote
0
answers
41
views
Advent of code 2023 day 8: Path finding in the desert - in pure Bash
Part 1
In today's task, a network of paths is defined like this:
LLR
AAA = (BBB, BBB)
BBB = (AAA, ZZZ)
ZZZ = (ZZZ, ZZZ)
The first line ...
2
votes
0
answers
92
views
Advent of code 2023 day 7: Ranking Camel Cards hands - mostly in Bash
Part 1
Today's task is to rank hands in a Camel Cards game and compute the total score.
In Camel Cards, you get a list of hands, and your goal is to order
them based on the strength of each hand. A ...
2
votes
0
answers
54
views
Advent of code 2023 day 6: Count ways to win boat race - in pure Bash
Part 1
To paraphrase the puzzle, given the times and record distances of boat races like this:
Time: 7 15 30
Distance: 9 40 200
That is, the first ...
3
votes
2
answers
82
views
Start script for several Spring Boot services
I have several Spring Boot and Angular applications/microservices that form together a whole application. As it is tedious to start them via the terminal, I've written the following script to perform ...
5
votes
2
answers
1k
views
Advent of code 2023 day 4: Count scratchcard points - mostly in Bash
Yesterday I thought was the last day of Advent Of Code 2023 that I do in Bash. I was wrong. I'm not even sure anymore that today will be the one. We'll just have to see tomorrow!
Part 1
To paraphrase ...
1
vote
0
answers
128
views
Advent of code 2023 day 3: count engine part numbers - in pure Bash
Yes I'll keep doing this until I cannot be bothered to do it in Bash ;-) (Well today is probably the last one ;-))
Part 1
To paraphrase the puzzle, given some input ("engine schematic") like ...
6
votes
2
answers
2k
views
Advent of code 2023 day 2: count possible qube games - in pure Bash
To paraphrase the puzzle, Santa takes a walk with an Elf, and they play a game involving a bag of colorful cubes. In each game, there is an unknown number of each colored cubes in the bag, and the Elf ...
5
votes
1
answer
235
views
Advent of code 2023 day 1: count trebuchet calibration numbers - mostly in Bash
It's that time of the year again!
Although there's no more Winter Bash, we can still have all the Bash we want in winter ;-)
Part 1
To paraphrase the description:
For each line in the input:
Find ...
-1
votes
1
answer
69
views
3
votes
1
answer
167
views
C++ Mock Library: Part 2
Parts
C++ Mock Library: Part 1
C++ Mock Library: Part 2
C++ Mock Library: Part 3
C++ Mock Library: Part 4
C++ Mock Library: Part 5
C++ Mock Library: Part 6
Removing redundant MOCK_SYS usage
After ...
3
votes
1
answer
125
views
VSCode-Portable Updater (MSYS2)
VSCode's portable mode doesn't support auto-updates, unlike its normal installer-based versions. I happen to use MSYS2's UCRT64 environment which makes the Linux tools I like play nice with the ...
5
votes
1
answer
108
views
Bash/perl function to search `lsblk` for drives whose partitions all match a filter
The following function searches for disks whose partitions all have an attribute that match a filter when listed with lsblk. Comments are in TomDoc format.
...
3
votes
1
answer
101
views
Bash/perl function for filtering and formatting `/etc/fstab`
The following function filters and formats /etc/fstab for future use. Comments are in TomDoc format.
...
5
votes
1
answer
165
views
Script to loop through a list of YouTube channels, and output metadata to a Markdown file
Overview
I have created a bash script (triggered via GitHub Actions) that does the following:
Parse a list of YouTube channel IDs and nicknames.
Fetch their metadata via YouTube's Channel API.
Build ...
1
vote
1
answer
52
views
Find missing files from subdirectories given the file names have sequential number
I have a directory structure like bellow.
...
3
votes
1
answer
105
views
Follow-up Q: Protein databank file chain, segment and residue number modifier
I asked a question yesterday (Protein databank file chain, segment and residue number modifier) and received a very informative answer by J_H whose feedback I have taken onboard. Some of the feedback ...
4
votes
1
answer
180
views
Protein databank file chain, segment and residue number modifier
My first non-trivial bash script after fully moving to Linux Mint last week is attached (modify_cccp_bundles.in). The script ...
2
votes
2
answers
102
views
Generate a checksum for this input
I am inputting a file of uniq -c | sort -nr and I need to
take the string from the file,
generate a unique id of the string and then
Output a pipe separated value ...
4
votes
2
answers
243
views
Replace values in key=value configuration files
I have a handful of files containing simple configuration in which I need to modify values. There are some useful constraints that simplify my implementation:
The file consists of single lines of ...
5
votes
1
answer
190
views
Processing large blocklists with GNU Parallel
This is an ongoing project that has undergone a major update to speed up list processing. Here is the homepage for anyone interested.
It processes lists defined in ...
2
votes
3
answers
100
views
Bash Script Conditionals for Commands and Testing
I know this is basic, being a Bash beginner, I like to learn the level of checking and testing when calling commands like; cp, mkdir, wget,... in a Bash function, and returning a result for the ...
1
vote
2
answers
159
views
Display free disk space
With Kubuntu 22.04 ...
Questions :
What is a better way than using 2 cases?
The 1st case, script Line 48 "case $x in"
lets user choose to clear screen or not clear.
The 2nd case, script ...