r_bash – Telegram
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
AI sucks, but so do I. Help needed.

Hi there,

I've been trying to get a bash noscript running properly on my synology for the last 10 hours, aided by chatGPT. With each iteration the AI offered, things worked for some time until they did not.

I want the noscript to run every 6 hours, so it has to self-terminate after each successful run. Otherwise Synology task scheduler will spit errors. I know that crontab exists, but I have SSH disabled usually and the DSM GUI only offers control over the built-in task scheduler and I want to pause the backup function at certain times without re-enabling SSH in order to access crontab.

I am trying to make an incremental backup of files on an FTP server. The folder /virtual contains hundreds of subfolders that are filled with many very small files. Each file is only a few to a few hundred bytes large.

Therefore, I asked chatGPT to write a noscript that does as follows:

1. Create an initial full backup of the folder /virtual
2. On the next run, copy all folders and files locally from the previous backup to a new folder with a current timestamp.
3. Connect to the FTP server and download only newly created or changed folders and/or files inside those folders.
4. terminate the noscript

This worked to a certain degree, but I noticed that a local copy of the previous folders into a new one with the current timestamp confuses lftp, hence downloading every file again.

From here on out everything got worse with every solution ChatGPT offered. Ignore the timestamps of the local folders, copy the folders with the previous timestamp, only check for changed files inside the folders and new folders against the initial backup....

At the end, the noscript was so buggy, it started to download all files and folders from the root directory of the FTP server. I gave up at this point.

Here is the noscript in its last, semi-working state.
It still downloads all 15k small files on each run, copies only the folder structure.
This is what I want to fix. Please keep in mind that I can only use FTP. No SFTP, no rsync.

Thanks a lot for your input!

`#!/bin/bash`

`# ========== CONFIGURATION ==========`

`FTP_HOST="serverIP"`

`FTP_USER="ftp-user"`

`FTP_PASS="password"`

`# Local backup paths`

`BASE_BACKUP_DIR="/volume/BackupServer/local_backup"`

`STORAGE_BACKUP_DIR="$BASE_BACKUP_DIR/storage"`

`VIRTUAL_BACKUP_DIR="$BASE_BACKUP_DIR/virtual"`

`LOG_DIR="$BASE_BACKUP_DIR/logs"`

`# Max backup versions to keep`

`MAX_ROTATIONS=120`

`# Timestamp`

`NOW=$(date +"%Y-%m-%d_%H-%M")`

`# Log file`

`mkdir -p "$LOG_DIR"`

`LOGFILE="$LOG_DIR/backup_$NOW.log"`

`# Lockfile to prevent concurrent execution`

`LOCKFILE="$BASE_BACKUP_DIR/backup_noscript.lock"`

`# ========== PREVENT MULTIPLE INSTANCES ==========`

`if [ -e "$LOCKFILE" ]; then`

`echo "[$(date +"%Y-%m-%d %H:%M:%S")] ERROR: Script is already running." | tee -a "$LOGFILE"`

`exit 1`

`fi`

`touch "$LOCKFILE"`

`trap 'rm -f "$LOCKFILE"; exit' INT TERM EXIT`

`# ========== FUNCTIONS ==========`

`rotate_backups() {`

`local dir=$1`

`cd "$dir" || exit 1`

`local backups=( $(ls -1d 20* 2>/dev/null | sort) )`

`local count=${#backups[@]}`

`if (( count >= MAX_ROTATIONS )); then`

`local to_delete=$((count - MAX_ROTATIONS + 1))`

`for ((i=0; i<to_delete; i++)); do`

`echo "Deleting old backup: ${backups[$i]}" | tee -a "$LOGFILE"`

`rm -rf "${backups[$i]}"`

`done`

`fi`

`}`

`cleanup_old_logs() {`

`echo "[*] Cleaning up log files older than 15 days..." | tee -a "$LOGFILE"`

`find "$LOG_DIR" -type f -name "backup_*.log" -mtime +15 -exec rm -f {} \;`

`}`

`backup_storage() {`

`echo "[*] Backing up /storage/backup/011" | tee -a "$LOGFILE"`

`local dest_dir="$STORAGE_BACKUP_DIR/$NOW"`

`mkdir -p "$dest_dir"`

`timeout 7200 lftp -u "$FTP_USER","$FTP_PASS" "$FTP_HOST" <<EOF 2>&1 | tee -a "$LOGFILE"`

`set ftp:passive-mode true`

`set net:timeout 300`

`set net:max-retries 2`

`mirror --verbose /ftpServer/main/folder/to/storage/backup/011 "$dest_dir/011"`

`quit`

`EOF`

`rotate_backups "$STORAGE_BACKUP_DIR"`

`}`

`backup_virtual_incremental() {`

`echo "[*] Backing
up /storage/virtual (incremental)" | tee -a "$LOGFILE"`

`local dest_dir="$VIRTUAL_BACKUP_DIR/$NOW"`

`mkdir -p "$dest_dir"`

`# === STEP 1: Copy entire content from previous backup before download ===`

`local last_backup=$(ls -1d "$VIRTUAL_BACKUP_DIR"/20* 2>/dev/null | sort | tail -n 1)`

`if [ -d "$last_backup" ]; then`

`echo "[*] Copying previous backup from $last_backup to $dest_dir..." | tee -a "$LOGFILE"`

`# Copy folder structure first`

`rsync -a --include='*/' --exclude='*' "$last_backup/" "$dest_dir/" | tee -a "$LOGFILE"`

`# Then copy files that don't exist yet`

`rsync -a --ignore-existing "$last_backup/" "$dest_dir/" | tee -a "$LOGFILE"`

`echo "[*] Copy from previous backup complete." | tee -a "$LOGFILE"`

`else`

`echo "[!] No previous backup found. Starting fresh." | tee -a "$LOGFILE"`

`fi`

`# === STEP 2: FTP mirror with only-newer logic ===`

`echo "[*] Downloading updated and new files from FTP..." | tee -a "$LOGFILE"`

`local lftp_log="/tmp/lftp_virtual_$$.log"`

`> "$lftp_log"`

`timeout 7200 lftp -u "$FTP_USER","$FTP_PASS" "$FTP_HOST" <<EOF > "$lftp_log" 2>&1`

`set ftp:passive-mode true`

`set net:timeout 300`

`set net:max-retries 2`

`mirror --only-newer --parallel=4 /ftpServer/main/folder/to/storage/virtual "$dest_dir"`

`quit`

`EOF`

`local changed_files_count`

`changed_files_count=$(grep -E '^Transferring|^=>|^<=|^Removing' "$lftp_log" | wc -l)`

`echo "[*] FTP sync complete. Files changed or added: $changed_files_count" | tee -a "$LOGFILE"`

`cat "$lftp_log" >> "$LOGFILE"`

`rm -f "$lftp_log"`

`rotate_backups "$VIRTUAL_BACKUP_DIR"`

`}`

`# ========== MAIN ==========`

`echo "===== Backup started at $NOW =====" | tee -a "$LOGFILE"`

`mkdir -p "$STORAGE_BACKUP_DIR"`

`mkdir -p "$VIRTUAL_BACKUP_DIR"`

`backup_storage`

`backup_virtual_incremental`

`cleanup_old_logs`

`echo "===== Backup finished at $(date +"%Y-%m-%d %H:%M:%S") =====" | tee -a "$LOGFILE"`

`# Cleanup`

`rm -f "$LOCKFILE"`

`trap - INT TERM EXIT`

https://redd.it/1na0c4p
@r_bash
declare -c var

Is declare -c var a reliable way of lower-casing all letters in a phrase except the first? That's what it appears to do (contrary to ChatGPT's assertion that it lower-cases all the letters). However, I can't find any documentation of the -c option.

https://redd.it/1nb6n57
@r_bash
Manipulate folder path in shell noscript variable

Greetings...

I've got kind of a dumb problem. I've got environment variables that define a path. Say for example
/var/log/somefolder/somefolder2

What I'm trying to do is set the folder to a path to the folder up two folders from that
/var/log

These aren't the folders... just trying to give a tangible example... the actual paths are dynamic.

I've set the variables to just append `../` which results in a variable that looks like this /var/log/somefolder/somefolder2/../../ and it seems like passing this variable into SOME functions / utilities works, but others it might not?

I am wondering if anyone has any great way to actually take the first folder and some how get the folder up some arbitrary number of folder levels up. I know dirname can give me the base, or parent of the current path, so should I just run dirname setting the newpath to the dirname of the original x number of times or is there an easier way?

https://redd.it/1nbp7ve
@r_bash
bash-completion behaving weirdly for some commands

Firstly, I most probably damaged something in some way, I do not remember these commands behaving like this before.

When I type commands like cargo or pacman, instead of printing the results to stdout and leaving the input line as-it-is, the results get inserted into the input line. Examples:
pacman ^I^I results in
pacman  --database files help query remove sync upgrade version -D F Q R S U V h 

pressing TAB more time prints seemingly all packages i have installed.
git ^I^I behaves as its supposed to.
cargo ^I^I inserts all subcommands to the input line, cargo add ^I^I results in:
cargo add -h --help -v --verbose -q --quiet --color -p --package --features --default-features --no-default-features --manifest-path --optional --no-optional --rename --dry-run --path --git --branch --tag --rev --registry --dev --build --target --ignore-rust-version

I have things like starship, but commenting out and starting new terminal and shell also does not resolve it. bash --norc and bash --norc --noprofile do not have the completion, and bash --noprofile has the concerned issue.

https://redd.it/1nchch3
@r_bash
bash-completion behaving weirdly

I most probably messed up. When i write commands like `cargo` or `pacman` (there are more), every subcommand or option gets written to the line. Glimpse:

https://preview.redd.it/6mifxk6mi4of1.png?width=686&format=png&auto=webp&s=ae27f8a70a89b8e755522a7f54f6eb56488bda8a

https://preview.redd.it/b13rsj6mi4of1.png?width=931&format=png&auto=webp&s=eac79af427043449bd247933704da6ba662064bc

What and why is this happening?

$ pacman -Qi bash-completion
Name : bash-completion
Version : 2.16.0-1
Denoscription : Programmable completion for the bash shell
Architecture : any
URL : https://github.com/scop/bash-completion
Licenses : GPL-2.0-only
Groups : None
Provides : None
Depends On : bash
Optional Deps : None
Required By : None
Optional For : bash bash-language-server packagekit
Conflicts With : None
Replaces : None
Installed Size : 1008.82 KiB
Packager : Tobias Powalowski <tpowa@archlinux.org>
Build Date : Thu Jan 16 13:21:28 2025
Install Date : Wed Sep 3 15:53:27 2025
Install Reason : Explicitly installed
Install Script : No
Validated By : Signature

I tried commenting out this from my bashrc:

# Use bash-completion, if available
# [[ $PS1 && -f /usr/share/bash-completion/bash_completion ]] &&
# . /usr/share/bash-completion/bash_completion

# # Completion for dotfiles
# [[ $PS1 && -f /usr/share/bash-completion/completions/git ]] &&
# . /usr/share/bash-completion/completions/git &&
# __git_complete dotfiles __git_main

But the issue is still there.

https://redd.it/1ncg8yy
@r_bash
Quotes around whole string or just the variable?

I've both but I'm unsure as to what is more correct because I can't seem to find any documentations on this.

fullpath="$HOME/"dir
full
path="$HOME/dir"

If we were to follow the style of the first line, it would fail in situations where there is a space between the variable and the string that is being concatenated, like in the following example.

message="$greeting Bob"
message="$greeting" Bob

The last line would fail because "Bob" would be treated as a command.

https://redd.it/1nd70h7
@r_bash
What is the best task project manager

I love the terminal. I have made it so I can do everything that isn't media rich in the terminal. I however keep struggling with one thing.

Project/task manager. I love the concept of task warrior and its super solid, but where I struggle is it doesn't really offer a good hierarchy. Yes I know about the subject.sub.sub but it doesn't lay it out in a clean way. Any suggestions?

https://redd.it/1nhxwzl
@r_bash
Questions about github workflow

Warning... Github newbie here... I finally got a github account going; I was ready to give up at one point. My current problem...
- I want to pull down a skeleton repo
- Throw in some text files, including an executable noscript
- Update and push the files to the repo and save changes

- The repo is https://github.com/NoAcadia3546/bash-conway-life/releases/tag/v0.1.0-alpha (it's public)
- On my desktop PC (linux) I'm in directory ~/life
- On desktop I execute

git pull https://github.com/NoAcadia3546/bash-conway-life/releases/tag/v0.1.0-alpha

...and I get the error message...

fatal: not a git repository (or any of the parent directories): .git

Did I not "finish" the repo, somehow? A separate question about "form"... should README.md contain the full documentation, or should it include a pointer to another file called "readme.txt"?

https://redd.it/1ni3faq
@r_bash
any reference about gtrash cmd?

Hi, I don't understand the use of trash-restore cmd, I don't understand where I should BE at the moment of restoring a file: in the destiny path of a file to be restored or in any other place. I don't understand how to get the numbered list of file....

May be this another cmd helps me: https://github.com/umlx5h/gtrash?tab=readme-ov-file

Thank you and Regards

https://redd.it/1niefrk
@r_bash
How can I convert all videos in a directory from webm to kmv using ffmpeg

this is the command to convert a webm to mk format is something like this

ffmpeg -i input.webm -c:v copy -c:a copy -c:s srt output.mkv

How do I do that to all the videos in a directory. Also, I would want the output to be the original file name, and the only change being the extension

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