r_bash – Telegram
Is there anyone who can help me fix my noscript?
https://redd.it/1q6vhzm
@r_bash
Script, software detection

Script, Software Detection

Hello, how do I write a noscript in bash that triggers an event when a program is launched? I made an example noscript to illustrate what I'm talking about. But of course, the reason I'm here is because the noscript doesn't work properly at all, but it's to illustrate the idea. I'm asking what the correct way to do it is.


While true; do

If pidof -x program > /dev/null ; then

echo "program launched "
exit
fi
sleep 1
donne

https://redd.it/1q5ts5u
@r_bash
Good jumping off point for shell noscripting? Looking for a tutorial or class.

I am not new to Linux, but I am a bit new to writing my own shell noscripts. I went through the Learn Linux TV tutorial. It was fun, but I am looking for something a bit more robust, with possibly some projects. Does anyone have any suggestions?


I've asked in a couple other forums and the answers were basically "Find something you want to automate and write a noscript for it." Yes... that's definitely my goal here, but I need a tiny bit more structure than that for my first few steps. I was wondering if there were any tried and true Youtube tutorials or something?

https://redd.it/1q8llzr
@r_bash
Is there anyway to tweak it to support multi-line lessons?
https://redd.it/1q8mzmd
@r_bash
Happy birthday, bash!
https://redd.it/1q8nzij
@r_bash
Quick and dirty noscript to generate denoscriptions of all programs in /usr/bin

I used ChatGPT to generate the original noscript, then modified it a bit after testing. It did exactly what I wanted it to do and I thought it was worth sharing.

Edit: formatted the code for readability

#!/bin/bash

# Written by ChatGPT, modified by Jeremy Thurman 1/9/2026
# Original prompt:
# "How would I write a bash noscript to list all the programs in /usr/bin and generate
# a brief denoscription of what they do?"

# A quick and dirty noscript to print a short denoscription of what every program in
# /usr/bin does.

# I remember installing a bunch of command line utilities, but I
# forgot what half of them even were or did. Or I remember installing programs to do
# some things, but forgot what they were called. This noscript goes along way
# towards solving both problems.

BIN_DIR="/usr/bin"
OUTPUT="program_denoscriptions.txt"

> "$OUTPUT"

for cmd in "$BIN_DIR"/*; do
# Only executables, not directories
[[ -x "$cmd" && ! -d "$cmd" ]] || continue

name=$(basename "$cmd")

# Try whatis first
desc=$(whatis "$name" 2>/dev/null | sed 's/^.* - //')

# Fallback to man -f if whatis doesn't return anything
if [[ -z "$desc" || "$desc" == "$name" ]]; then
desc=$(man -f "$name" 2>/dev/null | sed 's/^.* - //')
fi

# Skip it if no denoscription is available
if [[ -z "$desc" ]]; then
# desc="No denoscription available"
continue
fi

printf "%-30s : %s\n" "$name" "$desc" >> "$OUTPUT"

done

https://redd.it/1q8v9ai
@r_bash
Automations

Hey everyone
I'm working on making my Linux laptop very automated
I made a couple of noscripts that watch my files and copy paste their names into a local LLM that uses premade noscripts to move files
İt takes the name and format and now's exactly where everything should go inside each place so not videos go to video more like specific video goes to specific video inside videos
And I want more cool automation ideas like this


https://redd.it/1q91ss9
@r_bash
Confused by Globbing + Pattern Matching

Hey all,

Apologies if this isn't Bash-specific enough.

It seems like every time I'm writing basic regular expressions or globbing, I've got to re-learn the rules.

This is true of Bash versus ZSH (which is what I'll noscript in for CI, versus writing in the terminal); and regular expressions in more typical application development, like with Javanoscript or Go. This is made more confusing when, in the terminal, you layer on tools like FZF or Grep, which have their own problems (Linux vs. Mac compatibility and POSIX-compliant patterns, etc).

How do you all keep straight which rules apply? I'm having to look up the syntax for basic pattern matching (find me files with this extension, find me files with this prefix, find this substring on this line of text, etc) basically every time. Does this start to stick more with practice? I've been a terminal-based developer for like ~5 years and it's one of those things that I never remember.

Any recommendations on how to make this "stick" when writing noscripts? Do you have any helpful settings to make this simpler?

I feel like there is a constellation of footguns that prevents me from ever learning this stuff.

https://redd.it/1q96may
@r_bash
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