r_bash – Telegram
How to extract block separated by two newlines?

I have a text file. I want to extract the last block separated by two newline chars.

How to do that?

Example:



echo -e 'pre\n\nblock\nfirst\n\npost\n\nblock\nLAST\n\nsomechars'


How to get

block
LAST


?


https://redd.it/1n781cp
@r_bash
Help with bash noscript

Hi everyone, not sure if this is the correct place to ask for this, apologies if it isn't. I'm very new to bash and I'm trying to make a noscript that will scan all .md files in a specified directory (recursively, if possible) and extract all unique written paths (not links!). For example, an md file contains the following:

This is how you change the working directory:

    cd /example/path/foo/bar


So I want the noscript to return the string "/example/path/foo/bar" and which file(s) it was found in. It should ignore links to other files and also URLs. Is this possible? I feel stupid for struggling with this as much as I have

https://redd.it/1n7h1j6
@r_bash
No "isempty/0" ?? `jq 'select(.good-filenames | isempty)' data.jsonl`

Hi, I am fighting with Gemini AI, ChatGPT and Deepseek R1 about this line (and I am not sure whether to ask here or elsewhere)..

Can anybody tell me who is right?

jq 'select(.good-filenames | isempty)' data.jsonl`jq 'select(.good-filenames | isempty)' data.jsonl
jq: error: isempty/0 is not defined at <top-level>, line 1, column 30:
select(.["good-filenames"] | isempty)
^^^^^^^
jq: 1 compile error

For filtering all dicts where the array "good-filenames" is empty. Example:

{
"hash": "835618ffc68bbd70195dc4d189ff2b1f",
"good-filenames": [],
"bad_filenames": [
"stuff.txt"
]
}

# my binaries
> which jq
/home/user1/bin/jq
> /home/user1/bin/jq --version # which I downloaded from https://github.com/jqlang)
jq-1.8.1

From what I got from github (https://github.com/jqlang/jq/releases/tag/jq-1.8.1) there is ONLY `isempty/1` and no `isempty/0`. (looked through the Man pages etc!)

Who is right? The human or the 3 AIs?

https://redd.it/1n7a9em
@r_bash
I made a AI-powered CLI tool (No api calls) to convert natural language to shell commands

So here’s the thing: when I first started using the terminal, I honestly thought I needed a **PhD in Dark Arts & Arcane Spellcasting** just to do basic stuff.
Like…

>

After googling the *same damn commands* for the **500th time**, I had a thought:

>

So I thought maybe there was a tool that would help beginners and other people through without calling api or anything and should be light weight.
And boom **Shazam** was born (default name is Jarvis but you can call it Friday, Alfred, or even Papi if that’s your vibe).

# What it does:

You type this:

jarvis "change directory to Desktop"


And it prints this into your shell:

cd Desktop/


No ChatGPT API keys, no cloud BS, it runs a local GGUF model under the hood. And its quite light weight. To know more about how it works [click here](https://github.com/Sudheesh-07/shazam/blob/main/MODEL.md). If you want to contribute [repo is here](https://github.com/Sudheesh-07/shazam)

# Stuff I need help with:

* Currently it prints the command not on a readline but just as a output i want it to work on anew readline (I dont really know much about the low level programming to do so PS: codebase is in python)
* Making it play nice on various shells and OSs.
* Packaging it for Homebrew / apt so others can install it without issues.
* Smarter parsing → like remembering your context, chaining commands, etc.
* Basically everything that makes it cooler.

# Stuff that’s already in:

* Works in Bash, and Zsh
* Config file where you can rename your assistant (yes, you can call it Waifu if you want).
* Works througout your device no need to be in the root directory to use
* Can use -r or --run flag to directly execute

[Repo here](https://github.com/Sudheesh-07/shazam)

I legit think this could be a fun open-source project. With a lot of things to make it actually working and useful. So please feel to make contributions and make a great community project.

https://redd.it/1n82hqf
@r_bash
What are the most common reasons for a bash shell to get messed up?

Sometimes while scrolling backwards through my history, when I pass through a certain entry, the bash shell gets messed up. I seem to appear my PS1 and PS2 prompt string and the position of the cursor does no longer match if I actually edit a command. If later I watch the history, the edit was done at a different place than where the cursor was at.

Most of the times a reset command helps but not always.

Now I noticed something. The shell where I have the problem is in an i3 desktop that in itself runs in a remote desktop session. When I try to scroll through the exact same history when I SSH to the same host from Terminal.app on my Mac, I don't have the problem.

Might this be related to resizing of windows and the Bash shell not relying on correct information?

https://redd.it/1n829q3
@r_bash
Any recommended upload/download sites for this subreddit?

I'm currently doing the documentation/readme on my bash implementation of "Conway's Life Game". I don't see an option to upload attachments here. I'm a hobbyist, not a professional, and I have no idea how to set up and maintain a github repository like many people do here for downloading their creations. Is there a recommended site where I can upload a tarball for people to download? Right now I'm looking at approx 82 kbytes, which goes down to approx 16 kbytes as a .tgz file.

https://redd.it/1n8v1q5
@r_bash
How to Ctrl+C out of a noscript that uses timeout?

I have a file mynoscript with this content:

timeout 5 sleep 5


When I run bash mynoscript and use Ctrl+C, nothing happens. Is there some modification I can make to mynoscript where I can Ctrl+C to end the program before it waits for 5 seconds?

https://redd.it/1n9l9en
@r_bash
jb: Simple bash environment for Java project

I wrote this because sometimes I just need to whip up a Java application with a *.jar that runs, and:

I just don't have time to fire up Eclipse or IntelliJ;
I might not have graphical access to the system anyways;
I don't always have access to Maven infra;
I can't ever run jar correctly, the first time

This tool is helpful for me, because I tend to mainly do sysadmin work; or I troubleshoot systems that operate across a wide variety of languages and frameworks, or I may lack graphical access or Internet access. So I just need to write an application quickly to validate a concept in Java, or stand it up as a dummy, then move on.

Link: https://git.sr.ht/\~mehdyfaik/jb




https://redd.it/1n9jjyi
@r_bash
Newbie here - Need Help With Positioning Windows

Hello, i recently started to follow a bash coding course for beginners, i take notes and experiment with things i learn while following the course so i have 3 windows that are open all the time while i follow this course and for the sake of coding something that does something useful, i decided write a noscript that opens all those 3 windows and positions them as i prefer, so far noscript looks like this;

\#!/bin/bash

xed \~/Desktop/Studies/"note1.md" &

celluloid \~/Desktop/Studies/"plist1.m3u" &

xfce4-terminal &

sleep 5

wmctrl -r "note1.md (\~/Desktop/Studies)" -e 0,687,72,679,697 &

wmctrl -r "01 - Bash Scripting for Beginners: Complete Guide to Getting Started - Course Introduction (Part 1).mp4" -e 0,0,0,672,460 &

wmctrl -r "Terminal - vuaaaaaaa@vuaaaaaaa-E502SA: \~" -e 0,4,522,665,247 &

It works, but coordinates are a little bit messy and i don't know why, heres the "wmctrl -lG" for the correct layout of windows;

wmctrl -lG

0x03400003 0 7 522 665 247 vuaaaaaaa-E502SA Terminal - vuaaaaaaa@vuaaaaaaa-E502SA: \~

0x03800003 0 0 0 672 460 vuaaaaaaa-E502SA 01 - Bash Scripting for Beginners: Complete Guide to Getting Started - Course Introduction (Part 1).mp4

0x03600325 0 676 72 690 697 vuaaaaaaa-E502SA note1.md (\~/Desktop/Studies)



How it is supposed to look like

How it is looking

TLDR; Can't get coordinates of the windows that i am trying to open via a noscript right.

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