r_bash – Telegram
Getting parent dir of file without path in one step in pure bash?

Is there an easy way to get the parent dir of a file without the path in pure bash? Or, in other words, get the substring of a variable between the last and next-to-last slash?

I know of

path='/path/to/pardir/file'
dirpath="${path%/}"
pardir="${dirpath##
/}"
echo "$pardir"
pardir

With awk:

$ awk -F '/' '{sub(/\.^.+$/, "", $NF); print $(NF-1)}' <<< "$s"
$ pardir

and there's also expr match, although I'm not good with regexes. Not to mention dirname and basename.

Is there an easy, one-step incantation with pure bash so I can get this substring between the two last slashes?

https://redd.it/1li8ylt
@r_bash
Need help syntax error
https://redd.it/1liolod
@r_bash
bash2json - fully bash-written JSON parser

so, firstly it was created as a simple parser function for my another project, but i kinda wanted to make full JSON support in vanilla bash including arrays support, so it's fully written using bash substitution and builtins

i'd be happy to listen to any critics/suggestions
https://github.com/Tirito6626/bash2json

https://redd.it/1lkhk4i
@r_bash
fz - Pipe commands to FZF

Hello folks,

Last week, I was showing one of my functions sourced in .bashrc and .zshrc to one of my colleagues at work. He liked, then I decided to make it a Bash noscript on a GitHub repo, so more people can use it. Thus, I present fz - Pipe commands to FZF!

Before I share the repo with other colleagues, can you please review my code and give some comments? As a non-native English speaker, I will also appreciate if you double-check the documentation.

The purpose of the noscript is facilitating the usage of FZF with some common commands: man, ssh and kill. If you have some useful functions or alias that could be added to the noscript, please, don't hesitate to share.

Last, but not least, pull requests are welcome!

Thanks a lot! Hope you like it!

https://redd.it/1llnqc4
@r_bash
"File Transfer over SHell filesystem"

Hi all

If you run Midnight Commander, and open the Right or Left menu,
then you will see this:

https://i.ibb.co/BKfgjr4Q/1menu.png

There is a MenuItem there called "Shell Link",
and If you click it and then press F1 for help,
it will show you this screen:

https://i.ibb.co/8nNRsTRN/2help.png

In short, it says that bash contains a Remote File System feature,
but when I go to bash's documentation, I don't see any mentioning of it..

So does bash really has this feature?


Thank you

https://redd.it/1lmrtcu
@r_bash
bash2json v3 with speed tests

i just finished pretty stable bash2json v3 with huge perfomance improvents, thanks to everyone who suggested any of them
here are speed comparisons of v3, v2.3.0 and jq 1.6:

https://docs.tirito.de/bash2json/reference/results/

separate functions like query now can take as low as 3ms to finish, json validation and trim are around 1-2ms. removing forking gave a huge perfomance boost

https://redd.it/1lmx9ul
@r_bash
Ubuntu bash noscript to search for files containing certain words.

Hi all, I’m working on a Bash noscript that needs to:

Search the whole Linux filesystem (starting from /) for any files containing the text “secret” or “confidential”

For each word, count:

- How many files contain it

- The total number of occurrences across all files

- List the file names

I’m using grep -ril with --exclude-dir to avoid system folders like /proc, /sys, etc. The raw grep command works, but my loop and counting part don’t seem to produce output correctly. Any advice on how to structure this safely and correctly?

Ps:

Yes this is homework related but I've already spent a lot of time struggling so finally asking here.

The professor seems to think that throwing a unsolvable problem is some metric of "being tough". I'm totally lost as to what's the use case for such a noscript. This is what colleges are teaching these days under the banner of "cybersecurity" jfc.

https://redd.it/1lnnj5d
@r_bash
Reading directories and printing file names

Hey all

Looking to make a noscript that can read all directory names in a given path and then print the directory followed by all the files in that directory matching 'log' or 'conf' in that directory.

Something like:

This is a directory: /boot

These are the files in this directory: config-5.16.0-kali7-amd64,

This is a directory: /boot/firmware

These are the files in this directory: config.txt,

This is a directory: /boot/grub/i386-pc

These are the files in this directory: configfile.mod,

This is a directory: /dev

These are the files in this directory: log,

This is a directory: /etc

These are the files in this directory: adduser.conf,

This is a directory: /etc

These are the files in this directory: adduser.conf.dpkg-save,

This is a directory: /etc

These are the files in this directory: ca-certificates.conf,

This is a directory: /etc

These are the files in this directory: dconf,

This is a directory: /etc

These are the files in this directory: debconf.conf,

This is a directory: /etc

These are the files in this directory: deluser.conf,

This is a directory: /etc

These are the files in this directory: dns2tcpd.conf,



Yes this is for homework and ive spent hours on it, ai does it but i want to see how others approach it!

https://redd.it/1ln1tuc
@r_bash
problem with a noscript
https://redd.it/1loim99
@r_bash
Do you use process substitution in your Bash noscripts?

Discovered <(cmd) recently, super handy. How do you use it in your noscripts and anyone else using it regularly?

https://redd.it/1low2m3
@r_bash
Tool Release Smart-Shell: AI-Powered Terminal Assistant with Safety, Zsh & Web Search

Hey everyone — I just released a tool I’ve been working on called Smart-Shell.

🧠 It's an AI terminal assistant that converts plain English into safe Bash/Zsh commands — and it’s not just a wrapper around an API — Well tested on Bash.

Key Features:

AI-powered with Google Gemini (Pro/Flash)

Built-in 4-tier command risk analysis: Safe
🔵 Info Leak
🟡 Medium (sudo/system)
🔴 High (e.g. rm -rf)

REPL mode with smart shell detection

Supports special commands like !web, !update, !history, !creator, and more

Works with pipx, has tab completion, desktop entry, dry-run, etc.

Supports both Bash and Zsh!


📘 Docs: https://lusan-sapkota.github.io/smart-shell/
💻 GitHub: https://github.com/Lusan-sapkota/smart-shell

Happy to hear your feedback or ideas for improvement 🙌

https://redd.it/1lowr64
@r_bash
How to fix error 103: [[: not found ?
https://redd.it/1lpg2x8
@r_bash
Generating help-options from source with sed

Here's a gist of a few snippets I've been using with larger shell noscripts and makefiles. Since source location is readily accessible in both mediums, it's just a matter of parsing to use existing comments in your help options.



Someone could probably do it more cleanly with awk, but this seemed uniquely suited to sed's concept of hold space vs pattern space. As it parses the file, sed formats each comment and pushes it to the hold space like a stack. Then, when either a target or a function declaration is matched, it prints the name along with the comments from before.



It currently relies on the function keyword in bash, so the pattern could be more generic. Otherwise, there's plenty of room to format to taste and/or add ansi colors.

https://redd.it/1lpj7tm
@r_bash
Collecting Core/Thread/Storage Info from Many Linux Boxes

Got 100+ Linux machines. Need a quick inventory dump in CSV format. Just the basics per machine:

• CPU cores
• Threads per core
• Total storage
• Total memory
• Used memory
• Used storage

Not lookin’ for deep stats—just clean numbers I can toss in a dashboard.

https://redd.it/1lpwygj
@r_bash
Why does ls command list this in order I-III-II in Bash?
https://redd.it/1lp55ir
@r_bash