r_bash – Telegram
My Bash noscript is a bit slow, is there a better way to use 'find' file lists?

EDIT-Solution found at bottom

Script:

#!/usr/bin/bash

rm -fv plot.dat

find . -iname "output.txt" -exec sh -c '

BASE=$(tail -6 < {} | head -n 1 | cut -d " " -f 2)
FAKE=$(tail -3 < {} | head -n 1 | cut -d " " -f 2)
echo
$BASE $FAKE >> plot.dat

' {} \;

sort -k1 -n < plot.dat

echo "All done"

The noscript runs on 1,000's of files, and each file has 2k to 10k lines per file. All I really need to do is get the 6th last, and 3rd last lines of the files, and then the 2nd column (always an integer).

I think that tail+head+cut are probably not the issue, I think it might be the creation of thousands of shells through the "find -exec" portion.

Is there a way to get the file list into a variable (an array), and then maybe use a for loop to run the extraction code on the list? The performance isn't important, it still runs in about a minute, this is a question of curiosity about find+shell noscripts.

The bottom of the text files I am parsing look like this:

...
Fake: 34287094987
Fake: 34329141601
Fake: 34349349971
BASE: 1055
Prob Primes: 717268266
Primes: 717267168
Fakes: 1098
Fake %: 0.00015308%
Fake Rate: 1 in 653250

#SOLUTION

This speed-up is really good, from 1m10s to just 10s:

rm -fv plot.dat

for i in /output
.txt; do
BASE=$(tail -6 $i | head -n 1 | cut -d " " -f 2)
FAKE=$(tail -3 $i | head -n 1 | cut -d " " -f 2)
echo $BASE $FAKE >> plot.dat
done

https://redd.it/1q9q5pj
@r_bash
Me desafiei a usar o bash por uma semana.

Fiquei cada vez mais fan do bash por causa desse canal aqui... [yousuckatprogramming\](https://www.youtube.com/@yousuckatprogramming), mas tenho sérios problemas em sair do fish, é muito confortavel então eu vou dar uma chance porque não... como diria um filósofo do meu pais BRIO, quais as principais ferramentas que são uteis para um usário de bash.

https://redd.it/1q9zh1b
@r_bash
Need help inserting a variable into a quoted operand

Hi,

convert is an image conversion cli part of the imagemagick suite.

I want to use variables instead of manual entry of text. Example below.

ln1='The first line.' ; convert -pointsize 85 -fill white -draw 'text 40,100 ${ln1}"' -draw 'text 40,200 "The second line."' source.jpg out.jpg

The single quotes confuse me, I've tried different brackets and ways I know of. The help doc about the draw operand offers no examples, or if it's possible.

How can I use the ln1 variable successfully? Thanks.

https://redd.it/1qbhdbk
@r_bash
Why is the tar --use-compress-program-- here giving an error when extracting the file?


#!/usr/bin/env bash

function create_archive() {
if tar --create --directory="${HOME}/Desktop/noscripts" --file "test.tar.br" --use-compress-program="brotli --quality=6" "test"; then
echo "good"
else
echo "bad"
fi
}

function extract_archive() {
if tar --directory="${HOME}/Desktop/noscripts" --extract --file "test.tar.br" --use-compress-program="brotli --quality=6"; then
echo "good"
else
echo "bad"
fi
}

create_archive
extract_archive



- on running the above noscript i got this error

'/Users/g2g/Desktop/noscripts/tar_functions.sh'
good
tar: Error opening archive: Unrecognized archive format
bad

- why is the --use-compress-program not working when extracting?
- I am on the Apple M1 mac mini with Tahoe 26.1 if that helps

https://redd.it/1qbi0u7
@r_bash
Is there a cleaner way to string together an conditional expression for the find command? For example: find . -type f \( -iname "*.jpg" -o -iname "*.png" -o -iname "*.mp4" \) -print

I want to iterate a certain directory and get all the files that are pictures. So far I have this
`find . -type f \( -iname "*.jpg" -o -iname "*.png" -o -iname "*.mp4" \) -print`


But I know later I will want to expand the list of file types, and wanted an easier way. Is there a way I can do something like this?:

filetypes = [jpg, png, mp4, ... ]
find . -type f <filetypes> -print

https://redd.it/1qbjhye
@r_bash
How is bash noscripting different from other progamming languages?

Hi, I have been learning Linux. I am comfortable with shell commands and can write basic shell noscripts. I wanted to ask what bash noscripts does different than other programming languages like C or Python?

https://redd.it/1qbukhq
@r_bash
Bash Customization

I'm quite lost in what is the customization of bash in the terminal, I know it doesn't shine for this reason, but I decided to use bash and not zsh or fish.

Could you help me know what can be done?

https://redd.it/1qbw7ti
@r_bash
Is using a for loop like this okay in bash?

Maybe you saw my previous post, I got lots of answers but wanted to ask specifically about doing it this way:

# bash function to recursively search a directory and print all files that are photos or videos. An emphasis on making it easy to update the list of file types.

iterate() {
types=(
# photos
jpg jpeg jpe png gif bmp tiff tif webp heic heif avif
# videos
mp4 m4v mov avi mkv webm flv mpeg mpg 3gp 3g2 mts m2ts
# raw photos
dng cr2 cr3 nef arw orf rw2 pef raf srw
)

expr=()
for t in "${types[@]}"; do
expr+=( -iname "*.$t" -o )
done

find . -type f \( "${expr[@]}" -false \) -print
}

https://redd.it/1qby4jm
@r_bash
Help assigning variables that are partially determined by another variable to a different variable that's also partially determined by another variable

So, I need some help. Im trying to assign a value that's determined by one variable, with part of that variable being set by an additional variable, to another variable where part of it is set by an additional variable.

Below is what I need to do:


Characters entered:
XYZ

I need the output to fill up 5 characters, so I would want the result to be:
XYZXY



These are the variables starting out
char1=X
char2=Y
char3=Z
char4=
char5=

n=1

result1=0
reault2=0
result3=0
result4=0
result5=0


I also have a piece of code (that works perfectly fine) counting the number of characters entered. In this case, that code would set the following variable:

length=3





I would like to use the above variables in the following manner:
Until [[ "$length" -eq 5 ]]; do
length=$((length + 1)
result$length=char$n
n=$((n + 1))
Done



The output should ideally result in the variables being set as follows
char1=X
char2=Y
Char3=Z
Char4=X
char5=Y



I have tried using the
eval
command, but that seems to only work for one side of the variable setting. I tried changing the line:
result$length=char$n

to
 result$length=char$n

And that seems to only work for one side of the "=" Can anyone offer help on how to accomplish this?

Edit:

Unfortunately the result I'm getting is:
char1=X
char2=Y
char3=Z
char4=char1
char5=char2

That is not what I want...


https://redd.it/1qcslq9
@r_bash
Exclude file(s) from deletion

Hi everyone👋 New to Linux, thus bash, too. I want to delete an entire directory that only contains a series of mp3 files WITH THE EXCEPTION of 1-2 of them. Seems simple enough, rite? Not for me because all the files are very similar to each other with the exception of a few digits. How do I do that without moving the said file out of the directory? God I suck.

https://redd.it/1qd5pax
@r_bash
What exactly is a job?

According to Bash reference manual, a job is:

>A set of processes comprising a pipeline, and any processes descended from it, that are all in the same process group.

Does that mean cmd1 && cmd2 consists of two jobs (cmd2 is executed only if cmd1 succeeds)?

But if I do something like cmd1 && cmd2 & , then this whole list is executed in the background as a single job.

So I'm not able to grasp what consists of a job?

https://redd.it/1qdfdqy
@r_bash
Incognito-style shell for shared environments

Hi, I'm trying to put together an effective incognito-style shell session for shared environments. The idea is to keep it really quick and cheap to use, like a copy-paste single line you can run on any vm without installing anything.

I've been using a more primitive version for a while just to avoid shell command history but that doesn't cover other common tools. I'm not aiming for anonymity or sandboxing, just some practical hygiene when working on shared systems.

I'm posting mainly to get some feedback and ideas, edge cases I might have missed, history leaks you've run into on shared machines or simpler approaches that work better for this kind of lightweight ondemand usage. If you've spent time on shared VMs I'd love to hear any suggestions or critiques.

https://github.com/jazho76/private\_shell/

https://redd.it/1qdyes6
@r_bash
Simple Script to automate VMs Creation For Local Labs.

🚀 Excited to announce the release of KVM_Spin_Ups - Your Gateway to DevOps Excellence! 🚀

Just launched my latest open-source project: KVM_Spin_Ups - an Infrastructure as Code (IaC) tool that transforms your Linux workstation into a powerful virtualization
platform for rapid VM provisioning.

What makes it special?
• Zero-to-VM in minutes with automated provisioning
• Supports enterprise-grade distributions (Rocky Linux & AlmaLinux)
• Perfect for CI/CD pipeline testing, infrastructure automation, and multi-node cluster simulation
• No cloud costs - run production-like environments locally
• Built with DevOps best practices in mind

🛠️ Built with:
• KVM/QEMU virtualization
• Kickstart automation
• Bash noscripting with modular architecture
• Security-first approach with encrypted passwords

🎯 Perfect for:
• DevOps Engineers testing Ansible/Terraform noscripts
• SREs simulating multi-node clusters
• Developers creating isolated test environments
• Anyone learning enterprise Linux distributions

This project bridges the gap between development and operations by providing production-like environments on your local hardware. Whether you're testing infrastructure
automation, simulating clusters, or learning enterprise Linux, KVM_Spin_Ups provides the foundation for effective DevOps practices.

🔗 Check it out:
KVM\_Spin\_Ups

🤝 Contributions welcome!

https://redd.it/1qe5yak
@r_bash
This media is not supported in your browser
VIEW IN TELEGRAM
I didn’t think Bash could do this… until I built a Waybar timer in Bash
https://redd.it/1qekuhp
@r_bash
This media is not supported in your browser
VIEW IN TELEGRAM
I didn’t think Bash could do this… until I built a Waybar timer in Bash
https://redd.it/1qekuhp
@r_bash
My first shell noscripting project

For my first shell noscripting project/weekend project I made a nice CLI tool that when executed, prompts you to install common packages like sudo, curl, vim, lsof, rsync, etcetera. You can also include a -y flag in your command when executing the file to auto-install all the packages I included in the noscript.

This is also my first time publishing one of my projects like this on GitHub. I would love some feedback from people who know way more about this stuff than I do, and if nothing else, please enjoy the ASCII art.

https://github.com/benny01000010/linuxinstallhelper

https://redd.it/1qjig8s
@r_bash
I wrote a professional interrupt noscript that does a lot more than simply pause and I am trying to consider a unique name for what it does. Explanation below.

Originally I just simply called it pause. Nothing fancy, I was simply looking to create something like the pause command provided in DOS but I wanted to add the features that I wanted to be able to utilize in a sysadmin environment that I always had to hard code in.

This project was a great learning experience in bash coding and I learned a mountain of information doing this. I started out more so to save myself writing dozens of lines of code to get a timer and I would have to spend a couple hundred lines of code and still not getting what this offers up in a single command.

Once I discovered the internal monotonic clock I was on a mission to make a timer that could keep accurate time as long as the noscript is running and will accept timing down to 0.005 if needed. This is a high precision timer capable of fractional timing and millisecond captures but can simply say, "Press [Enter\] to continue..." and wait as long as it takes as a block timer or use the monotonic clock on a timer that checks for keypress every 0.01 seconds until the timer reaches zero. I have kept it so that there is little to no demand on the processor and the countdown only updates when needed. Script can be used as a "gatekeeper" for directing piped data. Data can be directed by command substitution into variables as needed.

All secondary information is sent to stderr while only the keypress and the gatekeeper piped information directed to stdout.

After some months of trial and error I finally am very close to a refined product. I will be releasing with GPL3.0+ license.

I added:

\-a, --allowed CHARS (Only defined characters to be considered valid keypress. Case sensitive. Valid keys can be A-Za-z0-9, Enter, space)

\-c, --case (change -a to case insensitive)

\-C, --color OPTIONS (allow colorization with optional foreground and background color values as well as attributes to prompt, timer, and response or none. default colors are prompt=blue, timer=red, response=green)

\-d,--default (the default key press to send to stdout for capturing if timer reaches zero without key press)

\-e, --echo (echo the key press to stdout for capture)

\-i, -in-pipe (use noscript as a gatekeeper noscript to capture and direct output to stdout.)

\-j, --json PATH (writes all variable and system data in single line output without jq allowing for use on Mac as well as Linux. JSON output is Splunk, ELK, etc, ready allowing easy integration into current setups. See -l,--log for more)

\-l, --log PATH (all internal system values and data can be shared to both .log and .json simultaneously. )

\-p, --prompt TEXT (change from the default prompt "Press [Enter\] to continue...")

\-q, --quiet (run quiet, no output to stderr except response. Fastest response times down to 0.005. Theoretical floor of 0.002 is possible but not without some processor overload)

\-r, --response TEXT (add response after continuation)

\-t, --timer SECONDS ( I have used a monotonic timer for the clock so there is no lag or jump with the clock and keeps accuracy for extended periods. I have also added fractional capabilities for quick server queries that with no text output has a floor of .005 seconds and 0.01 for text output intervals respectively. Timer format is [YYyr:MMmn:DDdy:HH:MM:SS\])

\-u, --urgent SECONDS (adds a bold red color to turn at the given number of seconds)

\-x, --extend (sends all variable and system data via stderr to either tyy/terminal [default\], [-l\] log file path or [-j\] json file path)

That is the extent of the options that I have included so far, not including help text for general use [-h, --help\] and color utilization [-Ch or --help-color\] and version [-v\] information.

I specifically designed this with the goal of only using bash internals for every task, updating to more modern internals depending on the bash version.

I have specifically designed in Mac 3.5 bash compatibility as well as
going down to internals in 2.0+ to be able to still used on very old machines.

The noscript is around 1100 lines at the moment and will be ready for final disclosure once I can find a permanent name that says more than simply "pause".

Any suggestions?

I would also like to hear what could be introduced that would make this a utility that would be more of benefit for the server side as well as the general user. I think I have a pretty good product right here and am excited to have others see the final product soon. 🙏 Thanks

https://redd.it/1qjlkiy
@r_bash
bash noscripts for the daily tasks

hey everyone! i’m sharing a small project that just hit what feels like a 1.0 version

---

## brief context
i started this project a few years ago as a collection of simple noscripts (that's why it has that name)

later i tried zsh + oh‑my‑zsh but never really took the time to learn how it all works

i moved back to bash (currently im using zsh and bash) and decided to build a clean, custom setup that still works in both bash and zsh, so i update the project

---

## what it is
simply, a collection of small helpers organized by topic/modules. the helpers are basically:

- noscripts (standalone commands)
- functions (run in the current shell context)
- aliases

the project has a simple noscript to setup all the things (in the README there is more context), basically the setup adds a block to your shell rc that wires the noscripts into PATH and loads the functions and aliases, maybe is like a oh-my-zsh but much much simpler hahaha

---


## what i learned
- improved my shell noscripting skills (-:
- learned more about bash vs zsh differences (especially config/behavior)
- got clearer on when to use noscripts vs functions vs aliases
- built a consistent structure to keep things maintainable

here is the link to the repo, any comments or feedback is welcome!









https://redd.it/1qjjaq2
@r_bash